AP_InertialSensor_Invensensev2_registers.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #pragma once
  2. #define REG_BANK0 0x00U
  3. #define REG_BANK1 0x01U
  4. #define REG_BANK2 0x02U
  5. #define REG_BANK3 0x03U
  6. #define INV2REG(b, r) ((((uint16_t)b) << 8)|(r))
  7. #define GET_BANK(r) ((r) >> 8)
  8. #define GET_REG(r) ((r) & 0xFFU)
  9. #define BIT_READ_FLAG 0x80
  10. #define BIT_I2C_SLVX_EN 0x80
  11. //Register Map
  12. #define INV2REG_WHO_AM_I INV2REG(REG_BANK0,0x00U)
  13. #define INV2REG_USER_CTRL INV2REG(REG_BANK0,0x03U)
  14. # define BIT_USER_CTRL_I2C_MST_RESET 0x02 // reset I2C Master (only applicable if I2C_MST_EN bit is set)
  15. # define BIT_USER_CTRL_SRAM_RESET 0x04 // Reset (i.e. clear) FIFO buffer
  16. # define BIT_USER_CTRL_DMP_RESET 0x08 // Reset DMP
  17. # define BIT_USER_CTRL_I2C_IF_DIS 0x10 // Disable primary I2C interface and enable hal.spi->interface
  18. # define BIT_USER_CTRL_I2C_MST_EN 0x20 // Enable MPU to act as the I2C Master to external slave sensors
  19. # define BIT_USER_CTRL_FIFO_EN 0x40 // Enable FIFO operations
  20. # define BIT_USER_CTRL_DMP_EN 0x80 // Enable DMP operations
  21. #define INV2REG_LP_CONFIG INV2REG(REG_BANK0,0x05U)
  22. #define INV2REG_PWR_MGMT_1 INV2REG(REG_BANK0,0x06U)
  23. # define BIT_PWR_MGMT_1_CLK_INTERNAL 0x00 // clock set to internal 8Mhz oscillator
  24. # define BIT_PWR_MGMT_1_CLK_AUTO 0x01 // PLL with X axis gyroscope reference
  25. # define BIT_PWR_MGMT_1_CLK_STOP 0x07 // Stops the clock and keeps the timing generator in reset
  26. # define BIT_PWR_MGMT_1_TEMP_DIS 0x08 // disable temperature sensor
  27. # define BIT_PWR_MGMT_1_SLEEP 0x40 // put sensor into low power sleep mode
  28. # define BIT_PWR_MGMT_1_DEVICE_RESET 0x80 // reset entire device
  29. #define INV2REG_PWR_MGMT_2 INV2REG(REG_BANK0,0x07U)
  30. #define INV2REG_INT_PIN_CFG INV2REG(REG_BANK0,0x0FU)
  31. # define BIT_BYPASS_EN 0x02
  32. # define BIT_INT_RD_CLEAR 0x10 // clear the interrupt when any read occurs
  33. # define BIT_LATCH_INT_EN 0x20 // latch data ready pin
  34. #define INV2REG_INT_ENABLE INV2REG(REG_BANK0,0x10U)
  35. # define BIT_PLL_RDY_EN 0x04
  36. #define INV2REG_INT_ENABLE_1 INV2REG(REG_BANK0,0x11U)
  37. #define INV2REG_INT_ENABLE_2 INV2REG(REG_BANK0,0x12U)
  38. #define INV2REG_INT_ENABLE_3 INV2REG(REG_BANK0,0x13U)
  39. #define INV2REG_I2C_MST_STATUS INV2REG(REG_BANK0,0x17U)
  40. #define INV2REG_INT_STATUS INV2REG(REG_BANK0,0x19U)
  41. #define INV2REG_INT_STATUS_1 INV2REG(REG_BANK0,0x1AU)
  42. #define INV2REG_INT_STATUS_2 INV2REG(REG_BANK0,0x1BU)
  43. #define INV2REG_INT_STATUS_3 INV2REG(REG_BANK0,0x1CU)
  44. #define INV2REG_DELAY_TIMEH INV2REG(REG_BANK0,0x28U)
  45. #define INV2REG_DELAY_TIMEL INV2REG(REG_BANK0,0x29U)
  46. #define INV2REG_ACCEL_XOUT_H INV2REG(REG_BANK0,0x2DU)
  47. #define INV2REG_ACCEL_XOUT_L INV2REG(REG_BANK0,0x2EU)
  48. #define INV2REG_ACCEL_YOUT_H INV2REG(REG_BANK0,0x2FU)
  49. #define INV2REG_ACCEL_YOUT_L INV2REG(REG_BANK0,0x30U)
  50. #define INV2REG_ACCEL_ZOUT_H INV2REG(REG_BANK0,0x31U)
  51. #define INV2REG_ACCEL_ZOUT_L INV2REG(REG_BANK0,0x32U)
  52. #define INV2REG_GYRO_XOUT_H INV2REG(REG_BANK0,0x33U)
  53. #define INV2REG_GYRO_XOUT_L INV2REG(REG_BANK0,0x34U)
  54. #define INV2REG_GYRO_YOUT_H INV2REG(REG_BANK0,0x35U)
  55. #define INV2REG_GYRO_YOUT_L INV2REG(REG_BANK0,0x36U)
  56. #define INV2REG_GYRO_ZOUT_H INV2REG(REG_BANK0,0x37U)
  57. #define INV2REG_GYRO_ZOUT_L INV2REG(REG_BANK0,0x38U)
  58. #define INV2REG_TEMP_OUT_H INV2REG(REG_BANK0,0x39U)
  59. #define INV2REG_TEMP_OUT_L INV2REG(REG_BANK0,0x3AU)
  60. #define INV2REG_EXT_SLV_SENS_DATA_00 INV2REG(REG_BANK0,0x3BU)
  61. #define INV2REG_EXT_SLV_SENS_DATA_01 INV2REG(REG_BANK0,0x3CU)
  62. #define INV2REG_EXT_SLV_SENS_DATA_02 INV2REG(REG_BANK0,0x3DU)
  63. #define INV2REG_EXT_SLV_SENS_DATA_03 INV2REG(REG_BANK0,0x3EU)
  64. #define INV2REG_EXT_SLV_SENS_DATA_04 INV2REG(REG_BANK0,0x3FU)
  65. #define INV2REG_EXT_SLV_SENS_DATA_05 INV2REG(REG_BANK0,0x40U)
  66. #define INV2REG_EXT_SLV_SENS_DATA_06 INV2REG(REG_BANK0,0x41U)
  67. #define INV2REG_EXT_SLV_SENS_DATA_07 INV2REG(REG_BANK0,0x42U)
  68. #define INV2REG_EXT_SLV_SENS_DATA_08 INV2REG(REG_BANK0,0x43U)
  69. #define INV2REG_EXT_SLV_SENS_DATA_09 INV2REG(REG_BANK0,0x44U)
  70. #define INV2REG_EXT_SLV_SENS_DATA_10 INV2REG(REG_BANK0,0x45U)
  71. #define INV2REG_EXT_SLV_SENS_DATA_11 INV2REG(REG_BANK0,0x46U)
  72. #define INV2REG_EXT_SLV_SENS_DATA_12 INV2REG(REG_BANK0,0x47U)
  73. #define INV2REG_EXT_SLV_SENS_DATA_13 INV2REG(REG_BANK0,0x48U)
  74. #define INV2REG_EXT_SLV_SENS_DATA_14 INV2REG(REG_BANK0,0x49U)
  75. #define INV2REG_EXT_SLV_SENS_DATA_15 INV2REG(REG_BANK0,0x4AU)
  76. #define INV2REG_EXT_SLV_SENS_DATA_16 INV2REG(REG_BANK0,0x4BU)
  77. #define INV2REG_EXT_SLV_SENS_DATA_17 INV2REG(REG_BANK0,0x4CU)
  78. #define INV2REG_EXT_SLV_SENS_DATA_18 INV2REG(REG_BANK0,0x4DU)
  79. #define INV2REG_EXT_SLV_SENS_DATA_19 INV2REG(REG_BANK0,0x4EU)
  80. #define INV2REG_EXT_SLV_SENS_DATA_20 INV2REG(REG_BANK0,0x4FU)
  81. #define INV2REG_EXT_SLV_SENS_DATA_21 INV2REG(REG_BANK0,0x50U)
  82. #define INV2REG_EXT_SLV_SENS_DATA_22 INV2REG(REG_BANK0,0x51U)
  83. #define INV2REG_EXT_SLV_SENS_DATA_23 INV2REG(REG_BANK0,0x52U)
  84. #define INV2REG_FIFO_EN_1 INV2REG(REG_BANK0,0x66U)
  85. # define BIT_SLV3_FIFO_EN 0x08
  86. # define BIT_SLV2_FIFO_EN 0x04
  87. # define BIT_SLV1_FIFO_EN 0x02
  88. # define BIT_SLV0_FIFI_EN0 0x01
  89. #define INV2REG_FIFO_EN_2 INV2REG(REG_BANK0,0x67U)
  90. # define BIT_ACCEL_FIFO_EN 0x10
  91. # define BIT_ZG_FIFO_EN 0x08
  92. # define BIT_YG_FIFO_EN 0x04
  93. # define BIT_XG_FIFO_EN 0x02
  94. # define BIT_TEMP_FIFO_EN 0x01
  95. #define INV2REG_FIFO_RST INV2REG(REG_BANK0,0x68U)
  96. #define INV2REG_FIFO_MODE INV2REG(REG_BANK0,0x69U)
  97. #define INV2REG_FIFO_COUNTH INV2REG(REG_BANK0,0x70U)
  98. #define INV2REG_FIFO_COUNTL INV2REG(REG_BANK0,0x71U)
  99. #define INV2REG_FIFO_R_W INV2REG(REG_BANK0,0x72U)
  100. #define INV2REG_DATA_RDY_STATUS INV2REG(REG_BANK0,0x74U)
  101. #define INV2REG_FIFO_CFG INV2REG(REG_BANK0,0x76U)
  102. #define INV2REG_SELF_TEST_X_GYRO INV2REG(REG_BANK1,0x02U)
  103. #define INV2REG_SELF_TEST_Y_GYRO INV2REG(REG_BANK1,0x03U)
  104. #define INV2REG_SELF_TEST_Z_GYRO INV2REG(REG_BANK1,0x04U)
  105. #define INV2REG_SELF_TEST_X_ACCEL INV2REG(REG_BANK1,0x0EU)
  106. #define INV2REG_SELF_TEST_Y_ACCEL INV2REG(REG_BANK1,0x0FU)
  107. #define INV2REG_SELF_TEST_Z_ACCEL INV2REG(REG_BANK1,0x10U)
  108. #define INV2REG_XA_OFFS_H INV2REG(REG_BANK1,0x14U)
  109. #define INV2REG_XA_OFFS_L INV2REG(REG_BANK1,0x15U)
  110. #define INV2REG_YA_OFFS_H INV2REG(REG_BANK1,0x17U)
  111. #define INV2REG_YA_OFFS_L INV2REG(REG_BANK1,0x18U)
  112. #define INV2REG_ZA_OFFS_H INV2REG(REG_BANK1,0x1AU)
  113. #define INV2REG_ZA_OFFS_L INV2REG(REG_BANK1,0x1BU)
  114. #define INV2REG_TIMEBASE_CORRECTIO INV2REG(REG_BANK1,0x28U)
  115. #define INV2REG_GYRO_SMPLRT_DIV INV2REG(REG_BANK2,0x00U)
  116. #define INV2REG_GYRO_CONFIG_1 INV2REG(REG_BANK2,0x01U)
  117. # define BIT_GYRO_NODLPF_9KHZ 0x00
  118. # define BIT_GYRO_DLPF_ENABLE 0x01
  119. # define GYRO_DLPF_CFG_229HZ 0x00
  120. # define GYRO_DLPF_CFG_188HZ 0x01
  121. # define GYRO_DLPF_CFG_154HZ 0x02
  122. # define GYRO_DLPF_CFG_73HZ 0x03
  123. # define GYRO_DLPF_CFG_35HZ 0x04
  124. # define GYRO_DLPF_CFG_17HZ 0x05
  125. # define GYRO_DLPF_CFG_9HZ 0x06
  126. # define GYRO_DLPF_CFG_376HZ 0x07
  127. # define GYRO_DLPF_CFG_SHIFT 0x03
  128. # define BITS_GYRO_FS_250DPS 0x00
  129. # define BITS_GYRO_FS_500DPS 0x02
  130. # define BITS_GYRO_FS_1000DPS 0x04
  131. # define BITS_GYRO_FS_2000DPS 0x06
  132. # define BITS_GYRO_FS_2000DPS_20649 0x04
  133. # define BITS_GYRO_FS_MASK 0x06 // only bits 1 and 2 are used for gyro full scale so use this to mask off other bits
  134. #define INV2REG_GYRO_CONFIG_2 INV2REG(REG_BANK2,0x02U)
  135. #define INV2REG_XG_OFFS_USRH INV2REG(REG_BANK2,0x03U)
  136. #define INV2REG_XG_OFFS_USRL INV2REG(REG_BANK2,0x04U)
  137. #define INV2REG_YG_OFFS_USRH INV2REG(REG_BANK2,0x05U)
  138. #define INV2REG_YG_OFFS_USRL INV2REG(REG_BANK2,0x06U)
  139. #define INV2REG_ZG_OFFS_USRH INV2REG(REG_BANK2,0x07U)
  140. #define INV2REG_ZG_OFFS_USRL INV2REG(REG_BANK2,0x08U)
  141. #define INV2REG_ODR_ALIGN_EN INV2REG(REG_BANK2,0x09U)
  142. #define INV2REG_ACCEL_SMPLRT_DIV_1 INV2REG(REG_BANK2,0x10U)
  143. #define INV2REG_ACCEL_SMPLRT_DIV_2 INV2REG(REG_BANK2,0x11U)
  144. #define INV2REG_ACCEL_INTEL_CTRL INV2REG(REG_BANK2,0x12U)
  145. #define INV2REG_ACCEL_WOM_THR INV2REG(REG_BANK2,0x13U)
  146. #define INV2REG_ACCEL_CONFIG INV2REG(REG_BANK2,0x14U)
  147. # define BIT_ACCEL_NODLPF_4_5KHZ 0x00
  148. # define BIT_ACCEL_DLPF_ENABLE 0x01
  149. # define ACCEL_DLPF_CFG_265HZ 0x00
  150. # define ACCEL_DLPF_CFG_136HZ 0x02
  151. # define ACCEL_DLPF_CFG_68HZ 0x03
  152. # define ACCEL_DLPF_CFG_34HZ 0x04
  153. # define ACCEL_DLPF_CFG_17HZ 0x05
  154. # define ACCEL_DLPF_CFG_8HZ 0x06
  155. # define ACCEL_DLPF_CFG_499HZ 0x07
  156. # define ACCEL_DLPF_CFG_SHIFT 0x03
  157. # define BITS_ACCEL_FS_2G 0x00
  158. # define BITS_ACCEL_FS_4G 0x02
  159. # define BITS_ACCEL_FS_8G 0x04
  160. # define BITS_ACCEL_FS_16G 0x06
  161. # define BITS_ACCEL_FS_30G_20649 0x06
  162. # define BITS_ACCEL_FS_MASK 0x06 // only bits 1 and 2 are used for gyro full scale so use this to mask off other bits
  163. #define INV2REG_FSYNC_CONFIG INV2REG(REG_BANK2,0x52U)
  164. # define FSYNC_CONFIG_EXT_SYNC_TEMP 0x01
  165. # define FSYNC_CONFIG_EXT_SYNC_GX 0x02
  166. # define FSYNC_CONFIG_EXT_SYNC_GY 0x03
  167. # define FSYNC_CONFIG_EXT_SYNC_GZ 0x04
  168. # define FSYNC_CONFIG_EXT_SYNC_AX 0x05
  169. # define FSYNC_CONFIG_EXT_SYNC_AY 0x06
  170. # define FSYNC_CONFIG_EXT_SYNC_AZ 0x07
  171. #define INV2REG_TEMP_CONFIG INV2REG(REG_BANK2,0x53U)
  172. #define INV2REG_MOD_CTRL_USR INV2REG(REG_BANK2,0x54U)
  173. #define INV2REG_I2C_MST_ODR_CONFIG INV2REG(REG_BANK3,0x00U)
  174. #define INV2REG_I2C_MST_CTRL INV2REG(REG_BANK3,0x01U)
  175. # define BIT_I2C_MST_P_NSR 0x10
  176. # define BIT_I2C_MST_CLK_400KHZ 0x0D
  177. #define INV2REG_I2C_MST_DELAY_CTRL INV2REG(REG_BANK3,0x02U)
  178. # define BIT_I2C_SLV0_DLY_EN 0x01
  179. # define BIT_I2C_SLV1_DLY_EN 0x02
  180. # define BIT_I2C_SLV2_DLY_EN 0x04
  181. # define BIT_I2C_SLV3_DLY_EN 0x08
  182. #define INV2REG_I2C_SLV0_ADDR INV2REG(REG_BANK3,0x03U)
  183. #define INV2REG_I2C_SLV0_REG INV2REG(REG_BANK3,0x04U)
  184. #define INV2REG_I2C_SLV0_CTRL INV2REG(REG_BANK3,0x05U)
  185. #define INV2REG_I2C_SLV0_DO INV2REG(REG_BANK3,0x06U)
  186. #define INV2REG_I2C_SLV1_ADDR INV2REG(REG_BANK3,0x07U)
  187. #define INV2REG_I2C_SLV1_REG INV2REG(REG_BANK3,0x08U)
  188. #define INV2REG_I2C_SLV1_CTRL INV2REG(REG_BANK3,0x09U)
  189. #define INV2REG_I2C_SLV1_DO INV2REG(REG_BANK3,0x0AU)
  190. #define INV2REG_I2C_SLV2_ADDR INV2REG(REG_BANK3,0x0BU)
  191. #define INV2REG_I2C_SLV2_REG INV2REG(REG_BANK3,0x0CU)
  192. #define INV2REG_I2C_SLV2_CTRL INV2REG(REG_BANK3,0x0DU)
  193. #define INV2REG_I2C_SLV2_DO INV2REG(REG_BANK3,0x0EU)
  194. #define INV2REG_I2C_SLV3_ADDR INV2REG(REG_BANK3,0x0FU)
  195. #define INV2REG_I2C_SLV3_REG INV2REG(REG_BANK3,0x10U)
  196. #define INV2REG_I2C_SLV3_CTRL INV2REG(REG_BANK3,0x11U)
  197. #define INV2REG_I2C_SLV3_DO INV2REG(REG_BANK3,0x12U)
  198. #define INV2REG_I2C_SLV4_ADDR INV2REG(REG_BANK3,0x13U)
  199. #define INV2REG_I2C_SLV4_REG INV2REG(REG_BANK3,0x14U)
  200. #define INV2REG_I2C_SLV4_CTRL INV2REG(REG_BANK3,0x15U)
  201. #define INV2REG_I2C_SLV4_DO INV2REG(REG_BANK3,0x16U)
  202. #define INV2REG_I2C_SLV4_DI INV2REG(REG_BANK3,0x17U)
  203. #define INV2REG_BANK_SEL 0x7F
  204. // WHOAMI values
  205. #define INV2_WHOAMI_ICM20648 0xe0
  206. #define INV2_WHOAMI_ICM20948 0xea
  207. #define INV2_WHOAMI_ICM20649 0xe1