mpu6050_dmp.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef MPU6050_H__
  2. #define MPU6050_H__
  3. #include "user_twim.h"
  4. #include "mygyro.h"
  5. #include "nrf_drv_gpiote.h"
  6. #define DEFAULT_MPU_HZ IMU_SF
  7. #define ACCEL_ON 0x01
  8. #define GYRO_ON 0x02
  9. #define MOTION 0
  10. #define NO_MOTION 1
  11. struct rx_s {
  12. uint8_t header[3];
  13. uint8_t cmd;
  14. };
  15. struct hal_s {
  16. uint8_t sensors;
  17. uint8_t dmp_on;
  18. uint8_t wait_for_tap;
  19. volatile uint8_t new_gyro;
  20. uint16_t report;
  21. uint16_t dmp_features;
  22. uint8_t motion_int_mode;
  23. struct rx_s rx;
  24. };
  25. typedef void (*set_acc_gyro_act_func)(void);
  26. typedef void (*set_sleep_act_func)(bool stat);
  27. //typedef void (*set_lowpower_act_func)(bool stat);
  28. typedef enum{
  29. MPU6050_NULL=0,
  30. MPU6050_INIT,
  31. MPU6050_ORIGIN,
  32. MPU6050_OFFSET,
  33. MPU6050_GET_DATA,
  34. MPU6050_SLEEP_ACT,
  35. MPU6050_SLEEP,
  36. MPU6050_NO_REG_ACT,
  37. MPU6050_NO_REG,
  38. MPU6050_WAKEUP,
  39. MPU6050_LOWPOWER_ACT,
  40. MPU6050_LOWPOWER,
  41. MPU6050_DELAY
  42. }MPU6050_WORK_STAT;
  43. typedef enum{
  44. MPU6050_LOWPOWER_DELAY,
  45. MPU6050_LOWPOWER_OFFSET,
  46. MPU6050_LOWPOWER_OFFSET_DELAY,
  47. MPU6050_LOWPOWER_ACTION
  48. }MPU6050_LOWPOWER_SEL;
  49. typedef struct{
  50. set_acc_gyro_act_func acc_gyro_func;
  51. set_sleep_act_func sleep_act_func;
  52. // set_lowpower_act_func lowpower_act_func;
  53. MPU6050_WORK_STAT work_stat;
  54. int16_t acc[3];
  55. int16_t gyro[3];
  56. bool offset_stat;
  57. MPU6050_LOWPOWER_SEL lowpower_stat;
  58. int8_t *gyro_orientation;
  59. bool sensor_stat;
  60. bool test_stop;
  61. }mpu6050_work_s;
  62. #define MPU6050_WORK_DEFAULT_CONFIG \
  63. { \
  64. .sleep_act_func=NULL, \
  65. .acc_gyro_func=NULL, \
  66. .work_stat=MPU6050_INIT, \
  67. .acc={0}, \
  68. .gyro={0}, \
  69. .offset_stat=false, \
  70. .lowpower_stat=MPU6050_LOWPOWER_DELAY, \
  71. .gyro_orientation=NULL, \
  72. .sensor_stat=false, \
  73. .test_stop=false, \
  74. };
  75. typedef enum
  76. {
  77. MPU6050_QUEUE_TIME=0,
  78. MPU6050_QUEUE_INT=1,
  79. MPU6050_QUEUE_SLEEP=2,
  80. }MPU6050_QUEUE_TYPE;
  81. bool mpu6050_init(void);
  82. void Set_Mpu6050_Queue(MPU6050_QUEUE_TYPE type);
  83. void mpu6050_dio_init(nrf_drv_gpiote_in_config_t *config,nrfx_gpiote_evt_handler_t evt_handler);
  84. /**
  85. @brief Function for writing a MPU6050 register contents over TWI.
  86. @param[in] register_address Register address to start writing to
  87. @param[in] value Value to write to register
  88. @retval true Register write succeeded
  89. @retval false Register write failed
  90. */
  91. static void mpu6050_register_write(uint8_t register_address, uint8_t value);
  92. /**
  93. @brief Function for reading MPU6050 register contents over TWI.
  94. Reads one or more consecutive registers.
  95. @param[in] register_address Register address to start reading from
  96. @param[in] number_of_bytes Number of bytes to read
  97. @param[out] destination Pointer to a data buffer where read data will be stored
  98. @retval true Register read succeeded
  99. @retval false Register read failed
  100. */
  101. static void mpu6050_read_write(uint8_t register_address);
  102. /**
  103. @brief Function for reading MPU6050 register contents over TWI.
  104. Reads one or more consecutive registers.
  105. @param[in] register_address Register address to start reading from
  106. @param[in] number_of_bytes Number of bytes to read
  107. @param[out] destination Pointer to a data buffer where read data will be stored
  108. @retval true Register read succeeded
  109. @retval false Register read failed
  110. */
  111. static void mpu6050_register_read(uint8_t * destination, uint8_t number_of_bytes);
  112. void mpu6050_timers_init(void);
  113. void Mpu6050_Start(uint32_t time);
  114. bool mpu6050_offset_start(void);
  115. void Set_Mpu6050_Value(void);
  116. void mpu6050_int_act(void);
  117. void mpu6050_set_sleep(void);
  118. void mpu6050_work_init(void);
  119. void mpu6050_set_no_reg(void);
  120. void set_mpu6050_sleep_act_func(set_sleep_act_func func);
  121. //void set_mpu6050_lowpower_act_func(set_lowpower_act_func func);
  122. void mpu6050_set_test_stop(void);
  123. int i2c_write(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *data);
  124. int i2c_read(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf);
  125. extern mpu6050_work_s mpu6050_work;
  126. extern my_gyro_t gyro_s;
  127. #endif //MPU6050_H__