Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MPU9150_nucleo_noni2cdev MPU9150_nucleo_noni2cdev_F401 JPEGCamera_SIM808_MPU9150_STM32F401RE
Fork of MPU9150_DMP by
MPU9150.h
00001 #ifndef MPU9150_INCLUDE 00002 #define MPU9150_INCLUDE 00003 00004 #include "mbed.h" 00005 #include "registers.h" 00006 #include "dmpdata.h" 00007 //https://github.com/sparkfun/MPU-9150_Breakout/blob/master/firmware/MPU6050/MPU6050_9Axis_MotionApps41.h 00008 00009 //extern Serial debug; 00010 00011 class MPU9150{ 00012 public: 00013 MPU9150(PinName scl, PinName sda, PinName interrupt, bool secondary_addr = false):i2c(sda, scl){ 00014 device_address = MPU6050_DEFAULT_ADDRESS; 00015 read_errors = 0; 00016 write_errors = 0; 00017 if(secondary_addr){ 00018 device_address = MPU6050_ADDRESS_AD0_HIGH; 00019 } 00020 00021 // i2c.frequency(400000); 00022 i2c.frequency(100000); 00023 } 00024 ~MPU9150(){} 00025 00026 bool getBit(char reg_addr, uint8_t bit); 00027 int8_t get8(char reg_addr); 00028 int16_t get16(char reg_addr); 00029 int16_t get16L(char reg_addr); 00030 00031 bool read(char reg_addr, char* data); 00032 bool read(char reg_addr, char* data, int length); 00033 bool readBit(char reg_addr, uint8_t bit_start, uint8_t *data); 00034 bool readBits(char reg_addr, uint8_t bit_start, uint8_t length, uint8_t *data); 00035 00036 bool write(char reg_addr, char data); 00037 bool write(char reg_addr, char* data, int length); 00038 bool writeBit(char reg_addr, uint8_t bit, bool value); 00039 bool writeBits(char reg_addr, uint8_t bit_start, uint8_t length, uint8_t data); 00040 00041 uint8_t getDeviceID(); 00042 bool isReady(); 00043 void initialise(); 00044 void initialiseMagnetometer(); 00045 void initialiseDMP(); 00046 00047 00048 //PWR_MGMT_1 Control Register 00049 void reset(); 00050 void sleep(bool state); 00051 void cycleMode(bool state); 00052 void disableTemperatureSensor(bool state); 00053 void clockSelect(uint8_t clk); 00054 00055 //PWR_MGMT_2 Control Register 00056 void setCycleWakeFrequency(uint8_t value); 00057 void setStandbyAccX( bool value ); 00058 void setStandbyAccY( bool value ); 00059 void setStandbyAccZ( bool value ); 00060 void setStandbyGyroX( bool value ); 00061 void setStandbyGyroY( bool value ); 00062 void setStandbyGyroZ( bool value ); 00063 00064 //SMPRT_DI Sample Rate Divider 00065 void setSampleRateDivider(uint8_t value); 00066 00067 //CONFIG 00068 void setExternalFrameSync(uint8_t value); 00069 void setDigitalLowPassFilter(uint8_t value); 00070 00071 //GYRO_CONFIG 00072 void setGyroSelfTest(bool value); 00073 void setGyroFullScaleRange(uint8_t value); 00074 00075 //ACCEL_CONFIG 00076 void setAccelSelfTest(bool value); 00077 void setAccelFullScaleRange(uint8_t value); 00078 00079 //FIFO_EN 00080 void setTemperatureFifo(bool value); 00081 void setGyroFifo(bool value); 00082 void setAccelFifo(bool value); 00083 void setSlave2Fifo(bool value); 00084 void setSlave1Fifo(bool value); 00085 void setSlave0Fifo(bool value); 00086 00087 //I2C_MST_CTRL 00088 void setMultiMaster(bool value); 00089 void setWaitForExternalSensor(bool value); 00090 void setSlave3Fifo(bool value); 00091 void setMasterStartStop(bool value); 00092 void setI2CMasterClock(uint8_t value); 00093 00094 //I2C_SLV0_ADDR 00095 void setI2cSlaveRW(uint8_t slave_id, bool value); 00096 void setI2cSlaveAddress(uint8_t slave_id, uint8_t value); 00097 //I2C_SLV0_REG, 00098 void setI2cSlaveRegister(uint8_t slave_id, uint8_t value); 00099 //I2C_SLV0_CTRL 00100 void setI2cSlaveEnable(uint8_t slave_id, bool value); 00101 void setI2cSlaveByteSwap(uint8_t slave_id, bool value); 00102 void setI2cSlaveRegDisable(uint8_t slave_id, bool value); 00103 void setI2cSlaveByteGrouping(uint8_t slave_id, bool value); 00104 void setI2cSlaveTransactionLength(uint8_t slave_id, uint8_t value); 00105 //I2C_SLV0_DO 00106 void setI2cSlaveDataOut(uint8_t slave_id, uint8_t value); 00107 //I2C_MST_DELAY_CTRL 00108 void setI2cSlaveDelay(uint8_t slave_id, uint8_t value); 00109 void setI2cSlaveShadowDelay(uint8_t value) ; 00110 //Slave4 is different 00111 void setI2cSlave4RW( bool value); 00112 void setI2cSlave4Address( uint8_t value); 00113 void setI2cSlave4Register(uint8_t value); 00114 void setI2cSlave4DataOut(uint8_t value); 00115 void setI2cSlave4Enable(bool value); 00116 void setI2cSlave4IntEnable(bool value); 00117 void setI2cSlave4RegDisable(bool value); 00118 void setI2cMasterDelay(uint8_t value); 00119 uint8_t getI2cSlave4Di(); 00120 00121 //I2C_MST_STATUS 00122 bool setI2cPassthrough(); 00123 bool setI2cSlave4Done(); 00124 bool setI2cLostArbitration(); 00125 bool setI2cSlave0Nack(); 00126 bool setI2cSlave1Nack(); 00127 bool setI2cSlave2Nack(); 00128 bool setI2cSlave3Nack(); 00129 bool setI2cSlave4Nack(); 00130 00131 //INT_PIN_CFG 00132 void setInterruptActiveLow(bool value); 00133 void setInterruptOpenDrain(bool value); 00134 void setInterruptLatch(bool value); 00135 void setInterruptAnyReadClear(bool value); 00136 void setFsyncInterruptActiveLow(bool value); 00137 void setFsyncInterruptEnable(bool value); 00138 void setI2cAuxBypassEnable(bool value); 00139 00140 //INT_ENABLE 00141 void setInterruptFifoOverflowEnable(bool value); 00142 void setInterruptMasterEnable(bool value); 00143 void setInterruptDataReadyEnable(bool value); 00144 00145 //INT_STATUS 00146 bool getInterruptFifoOverflow(); 00147 bool getInterruptMaster(); 00148 bool getInterruptDataReady(); 00149 uint8_t getInterruptStatus(); 00150 00151 //SIGNAL_PATH_RESET 00152 void resetGyroSignalPath(); 00153 void resetAccelSignalPath(); 00154 void resetTempSignalPath(); 00155 00156 //USER_CTRL 00157 void setEnableFifo(bool value); 00158 void setI2cMasterEnable(bool value); 00159 void setFifoReset(bool value); 00160 void setI2cMasterReset(bool value); 00161 void setFullSensorReset(bool value); 00162 00163 //FIFO_COUNT_H and FIFO_COUNT_L 00164 int16_t getFifoCount(); 00165 00166 //FIFO_R_W 00167 bool getFifoBuffer(char* buffer, int16_t length); 00168 00169 //UNDOCUMENTED 00170 // XG_OFFS_TC 00171 uint8_t getOTPBankValid(); 00172 00173 //INT_ENABLE 00174 void setIntPLLReadyEnabled(bool value); 00175 void setIntDMPEnabled(bool value); 00176 00177 // INT_STATUS 00178 bool getIntPLLReadyStatus(); 00179 bool getIntDMPStatus(); 00180 00181 // USER_CTRL 00182 bool getDMPEnabled(); 00183 void setDMPEnabled(bool value); 00184 void resetDMP(); 00185 00186 // BANK_SEL 00187 void setMemoryBank(uint8_t bank, bool prefetchEnabled=false, bool userBank=false); 00188 00189 // MEM_START_ADDR 00190 void setMemoryStartAddress(uint8_t address); 00191 00192 // MEM_R_W register 00193 uint8_t readMemoryByte(); 00194 void writeMemoryByte(uint8_t value); 00195 void readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address); 00196 bool writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank = 0, uint8_t address = 0, bool verify = false); 00197 bool writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize); 00198 00199 // DMP_CFG_1 00200 uint8_t getDMPConfig1(); 00201 void setDMPConfig1(uint8_t config); 00202 00203 // DMP_CFG_2 00204 uint8_t getDMPConfig2(); 00205 void setDMPConfig2(uint8_t config); 00206 00207 I2C i2c; 00208 uint8_t device_address; 00209 uint32_t read_errors; 00210 uint32_t write_errors; 00211 }; 00212 00213 #endif
Generated on Tue Jul 12 2022 21:16:03 by
1.7.2
