inv_mpu(5107).h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. $License:
  3. Copyright (C) 2011-2012 InvenSense Corporation, All Rights Reserved.
  4. See included License.txt for License information.
  5. $
  6. */
  7. /**
  8. * @addtogroup DRIVERS Sensor Driver Layer
  9. * @brief Hardware drivers to communicate with sensors via I2C.
  10. *
  11. * @{
  12. * @file inv_mpu.h
  13. * @brief An I2C-based driver for Invensense gyroscopes.
  14. * @details This driver currently works for the following devices:
  15. * MPU6050
  16. * MPU6500
  17. * MPU9150 (or MPU6050 w/ AK8975 on the auxiliary bus)
  18. * MPU9250 (or MPU6500 w/ AK8963 on the auxiliary bus)
  19. */
  20. #ifndef _INV_MPU_H_
  21. #define _INV_MPU_H_
  22. #include "stm32f1xx_hal.h"
  23. #define MPU6050 /* 定义为使用的传感器MPU6050 */
  24. #define MOTION_DRIVER_TARGET_MSP430 /* 定义驱动部分,采用MSP430的驱动(移植到STM32) */
  25. #define DEFAULT_MPU_HZ (100) /* 定义采样速率 */
  26. #define q30 (1073741824.0f) /* 2^30 = 1073741824 */
  27. #define INV_X_GYRO (0x40)
  28. #define INV_Y_GYRO (0x20)
  29. #define INV_Z_GYRO (0x10)
  30. #define INV_XYZ_GYRO (INV_X_GYRO | INV_Y_GYRO | INV_Z_GYRO)
  31. #define INV_XYZ_ACCEL (0x08)
  32. #define INV_XYZ_COMPASS (0x01)
  33. struct int_param_s {
  34. #if defined EMPL_TARGET_MSP430 || defined MOTION_DRIVER_TARGET_MSP430
  35. void (*cb)(void);
  36. unsigned short pin;
  37. unsigned char lp_exit;
  38. unsigned char active_low;
  39. #elif defined EMPL_TARGET_UC3L0
  40. unsigned long pin;
  41. void (*cb)(volatile void*);
  42. void *arg;
  43. #endif
  44. };
  45. #define MPU_INT_STATUS_DATA_READY (0x0001)
  46. #define MPU_INT_STATUS_DMP (0x0002)
  47. #define MPU_INT_STATUS_PLL_READY (0x0004)
  48. #define MPU_INT_STATUS_I2C_MST (0x0008)
  49. #define MPU_INT_STATUS_FIFO_OVERFLOW (0x0010)
  50. #define MPU_INT_STATUS_ZMOT (0x0020)
  51. #define MPU_INT_STATUS_MOT (0x0040)
  52. #define MPU_INT_STATUS_FREE_FALL (0x0080)
  53. #define MPU_INT_STATUS_DMP_0 (0x0100)
  54. #define MPU_INT_STATUS_DMP_1 (0x0200)
  55. #define MPU_INT_STATUS_DMP_2 (0x0400)
  56. #define MPU_INT_STATUS_DMP_3 (0x0800)
  57. #define MPU_INT_STATUS_DMP_4 (0x1000)
  58. #define MPU_INT_STATUS_DMP_5 (0x2000)
  59. /* Set up APIs */
  60. int mpu_init(struct int_param_s *int_param);
  61. int mpu_init_slave(void);
  62. int mpu_set_bypass(unsigned char bypass_on);
  63. /* Configuration APIs */
  64. int mpu_lp_accel_mode(unsigned char rate);
  65. int mpu_lp_motion_interrupt(unsigned short thresh, unsigned char time,
  66. unsigned char lpa_freq);
  67. int mpu_set_int_level(unsigned char active_low);
  68. int mpu_set_int_latched(unsigned char enable);
  69. int mpu_set_dmp_state(unsigned char enable);
  70. int mpu_get_dmp_state(unsigned char *enabled);
  71. int mpu_get_lpf(unsigned short *lpf);
  72. int mpu_set_lpf(unsigned short lpf);
  73. int mpu_get_gyro_fsr(unsigned short *fsr);
  74. int mpu_set_gyro_fsr(unsigned short fsr);
  75. int mpu_get_accel_fsr(unsigned char *fsr);
  76. int mpu_set_accel_fsr(unsigned char fsr);
  77. int mpu_get_compass_fsr(unsigned short *fsr);
  78. int mpu_get_gyro_sens(float *sens);
  79. int mpu_get_accel_sens(unsigned short *sens);
  80. int mpu_get_sample_rate(unsigned short *rate);
  81. int mpu_set_sample_rate(unsigned short rate);
  82. int mpu_get_compass_sample_rate(unsigned short *rate);
  83. int mpu_set_compass_sample_rate(unsigned short rate);
  84. int mpu_get_fifo_config(unsigned char *sensors);
  85. int mpu_configure_fifo(unsigned char sensors);
  86. int mpu_get_power_state(unsigned char *power_on);
  87. int mpu_set_sensors(unsigned char sensors);
  88. int mpu_set_accel_bias(const long *accel_bias);
  89. /* Data getter/setter APIs */
  90. int mpu_get_gyro_reg(short *data, unsigned long *timestamp);
  91. int mpu_get_accel_reg(short *data, unsigned long *timestamp);
  92. int mpu_get_compass_reg(short *data, unsigned long *timestamp);
  93. int mpu_get_temperature(long *data, unsigned long *timestamp);
  94. int mpu_get_int_status(short *status);
  95. int mpu_read_fifo(short *gyro, short *accel, unsigned long *timestamp,
  96. unsigned char *sensors, unsigned char *more);
  97. int mpu_read_fifo_stream(unsigned short length, unsigned char *data,
  98. unsigned char *more);
  99. int mpu_reset_fifo(void);
  100. int mpu_write_mem(unsigned short mem_addr, unsigned short length,
  101. unsigned char *data);
  102. int mpu_read_mem(unsigned short mem_addr, unsigned short length,
  103. unsigned char *data);
  104. int mpu_load_firmware(unsigned short length, const unsigned char *firmware,
  105. unsigned short start_addr, unsigned short sample_rate);
  106. int mpu_reg_dump(void);
  107. int mpu_read_reg(unsigned char reg, unsigned char *data);
  108. int mpu_run_self_test(long *gyro, long *accel);
  109. int mpu_register_tap_cb(void (*func)(unsigned char, unsigned char));
  110. uint8_t atk_ms6050_dmp_init(void);
  111. int atk_ms6050_get_clock_ms(unsigned long *count);
  112. uint8_t atk_ms6050_run_self_test(void);
  113. uint8_t atk_ms6050_dmp_get_data(float *pitch, float *roll, float *yaw);
  114. #endif /* #ifndef _INV_MPU_H_ */