#ifndef MPU6050_H__ #define MPU6050_H__ #include "user_twim.h" #include "mygyro.h" #include "nrf_drv_gpiote.h" #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 enum{ MPU6050_NULL=0, MPU6050_INIT, MPU6050_ORIGIN, MPU6050_OFFSET, MPU6050_GET_DATA, MPU6050_SLEEP_ACT, MPU6050_SLEEP, MPU6050_NO_REG_ACT, MPU6050_NO_REG, MPU6050_WAKEUP, MPU6050_LOWPOWER_ACT, MPU6050_LOWPOWER, MPU6050_DELAY }MPU6050_WORK_STAT; typedef enum{ MPU6050_LOWPOWER_DELAY, MPU6050_LOWPOWER_OFFSET, MPU6050_LOWPOWER_OFFSET_DELAY, MPU6050_LOWPOWER_ACTION }MPU6050_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; MPU6050_WORK_STAT work_stat; int16_t acc[3]; int16_t gyro[3]; bool offset_stat; MPU6050_LOWPOWER_SEL lowpower_stat; int8_t *gyro_orientation; bool sensor_stat; bool test_stop; }mpu6050_work_s; #define MPU6050_WORK_DEFAULT_CONFIG \ { \ .sleep_act_func=NULL, \ .acc_gyro_func=NULL, \ .work_stat=MPU6050_INIT, \ .acc={0}, \ .gyro={0}, \ .offset_stat=false, \ .lowpower_stat=MPU6050_LOWPOWER_DELAY, \ .gyro_orientation=NULL, \ .sensor_stat=false, \ .test_stop=false, \ }; typedef enum { MPU6050_QUEUE_TIME=0, MPU6050_QUEUE_INT=1, MPU6050_QUEUE_SLEEP=2, }MPU6050_QUEUE_TYPE; bool mpu6050_init(void); void Set_Mpu6050_Queue(MPU6050_QUEUE_TYPE type); void mpu6050_dio_init(nrf_drv_gpiote_in_config_t *config,nrfx_gpiote_evt_handler_t evt_handler); /** @brief Function for writing a MPU6050 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 mpu6050_register_write(uint8_t register_address, uint8_t value); /** @brief Function for reading MPU6050 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 mpu6050_read_write(uint8_t register_address); /** @brief Function for reading MPU6050 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 mpu6050_register_read(uint8_t * destination, uint8_t number_of_bytes); void mpu6050_timers_init(void); void Mpu6050_Start(uint32_t time); bool mpu6050_offset_start(void); void Set_Mpu6050_Value(void); void mpu6050_int_act(void); void mpu6050_set_sleep(void); void mpu6050_work_init(void); void mpu6050_set_no_reg(void); void set_mpu6050_sleep_act_func(set_sleep_act_func func); //void set_mpu6050_lowpower_act_func(set_lowpower_act_func func); void mpu6050_set_test_stop(void); 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); extern mpu6050_work_s mpu6050_work; extern my_gyro_t gyro_s; #endif //MPU6050_H__