123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #ifndef MPU_H__
- #define MPU_H__
- #include "user_twim.h"
- #include "mygyro.h"
- #include "nrf_drv_gpiote.h"
- #define MPU_CS_ENABLE nrf_gpio_pin_write(MPU_SS_PIN, 0);
- #define MPU_CS_DISABLE nrf_gpio_pin_write(MPU_SS_PIN, 1);
- #define DEFAULT_MPU_HZ IMU_SF
- #define ACCEL_ON 0x01
- #define GYRO_ON 0x02
- #define MOTION 0
- #define NO_MOTION 1
- struct rx_s {
- uint8_t header[3];
- uint8_t cmd;
- };
- struct hal_s {
- uint8_t sensors;
- uint8_t dmp_on;
- uint8_t wait_for_tap;
- volatile uint8_t new_gyro;
- uint16_t report;
- uint16_t dmp_features;
- uint8_t motion_int_mode;
- struct rx_s rx;
- };
- typedef void (*set_acc_gyro_act_func)(void);
- typedef void (*set_sleep_act_func)(bool stat);
- //typedef void (*set_lowpower_act_func)(bool stat);
- typedef bool (*get_mpu_testing_act_func)(void);
- typedef void (*mpu_check_finish_func)(void);
- typedef enum{
- MPU_NULL=0,
- MPU_INIT,
- MPU_ORIGIN,
- MPU_OFFSET,
- MPU_GET_DATA,
- MPU_SLEEP_ACT,
- MPU_SLEEP,
- MPU_NO_REG_ACT,
- MPU_NO_REG,
- MPU_WAKEUP,
- MPU_LOWPOWER_ACT,
- MPU_LOWPOWER,
- MPU_DELAY,
- MPU_FAULT,
- }MPU_WORK_STAT;
- typedef enum{
- MPU_LOWPOWER_DELAY,
- MPU_LOWPOWER_OFFSET,
- MPU_LOWPOWER_OFFSET_DELAY,
- MPU_LOWPOWER_ACTION
- }MPU_LOWPOWER_SEL;
- typedef struct{
- set_acc_gyro_act_func acc_gyro_func;
- set_sleep_act_func sleep_act_func;
- // set_lowpower_act_func lowpower_act_func;
- get_mpu_testing_act_func mpu_testing_act_func;
- mpu_check_finish_func check_finish_func ;
- MPU_WORK_STAT work_stat;
- int16_t acc[3];
- int16_t gyro[3];
- bool offset_stat;
- MPU_LOWPOWER_SEL lowpower_stat;
- int8_t *gyro_orientation;
- uint8_t sensor_stat;
- bool test_stop;
- uint32_t mpu_wakeup;
- }mpu_work_s;
- #define MPU_WORK_DEFAULT_CONFIG \
- { \
- .sleep_act_func=NULL, \
- .acc_gyro_func=NULL, \
- .work_stat=MPU_INIT, \
- .acc={0}, \
- .gyro={0}, \
- .offset_stat=false, \
- .lowpower_stat=MPU_LOWPOWER_DELAY, \
- .gyro_orientation=NULL, \
- .sensor_stat=0, \
- .test_stop=false, \
- .mpu_wakeup=0, \
- };
- typedef enum
- {
- MPU_QUEUE_TIME=0,
- MPU_QUEUE_INT=1,
- MPU_QUEUE_SLEEP=2,
- }MPU_QUEUE_TYPE;
- void Set_Mpu_Queue(MPU_QUEUE_TYPE type);
- void mpu_dio_init(nrf_drv_gpiote_in_config_t *config,nrfx_gpiote_evt_handler_t evt_handler);
- /**
- @brief Function for writing a mpu register contents over TWI.
- @param[in] register_address Register address to start writing to
- @param[in] value Value to write to register
- @retval true Register write succeeded
- @retval false Register write failed
- */
- static void mpu_register_write(uint8_t register_address, uint8_t value);
- /**
- @brief Function for reading mpu register contents over TWI.
- Reads one or more consecutive registers.
- @param[in] register_address Register address to start reading from
- @param[in] number_of_bytes Number of bytes to read
- @param[out] destination Pointer to a data buffer where read data will be stored
- @retval true Register read succeeded
- @retval false Register read failed
- */
- static void mpu_read_write(uint8_t register_address);
- /**
- @brief Function for reading mpu register contents over TWI.
- Reads one or more consecutive registers.
- @param[in] register_address Register address to start reading from
- @param[in] number_of_bytes Number of bytes to read
- @param[out] destination Pointer to a data buffer where read data will be stored
- @retval true Register read succeeded
- @retval false Register read failed
- */
- static void mpu_register_read(uint8_t * destination, uint8_t number_of_bytes);
- void mpu_timers_init(void);
- void mpu_Start(uint32_t time);
- bool mpu_offset_start(void);
- void Set_Mpu_Value(void);
- void mpu_int_act(void);
- void mpu_set_sleep(void);
- void mpu_work_init(void);
- void mpu_set_no_reg(void);
- void set_mpu_sleep_act_func(set_sleep_act_func func);
- //void set_mpu_lowpower_act_func(set_lowpower_act_func func);
- void set_mpu_testing_act_func(get_mpu_testing_act_func func);
- void set_mpu_check_finish_func(mpu_check_finish_func func);
- void mpu_set_test_stop(void);
- #ifdef MPU_SPI
- void mpu_spi_ss_init(void);
- int spi_write(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *data);
- int spi_read(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf);
- #else
- int i2c_write(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *data);
- int i2c_read(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf);
- #endif
- extern mpu_work_s mpu_work;
- extern my_gyro_t gyro_s;
- #endif //MPU_H__
|