Fire_RT1021_EVK_FSPIAsSPI/include/mpu6500.h

52 lines
1.5 KiB
C

#ifndef MPU6500_H
#define MPU6500_H
#include <stdint.h>
typedef enum {
MPU6500_RET_SUCCESS,
MPU6500_RET_FAIL,
} mpu6500_ret_t;
typedef enum {
MPU6500_CH_TEMP = 0x41U,
MPU6500_CH_ACCEL_X = 0x3BU,
MPU6500_CH_ACCEL_Y = 0x3DU,
MPU6500_CH_ACCEL_Z = 0x3FU,
MPU6500_CH_GYRO_X = 0x43U,
MPU6500_CH_GYRO_Y = 0x45U,
MPU6500_CH_GYRO_Z = 0x47U,
} mpu6500_channel_t;
typedef struct {
int16_t temp_raw;
int16_t accel_x_raw;
int16_t accel_y_raw;
int16_t accel_z_raw;
int16_t gyro_x_raw;
int16_t gyro_y_raw;
int16_t gyro_z_raw;
} mpu6500_result_t;
typedef mpu6500_ret_t (*mpu6500_ops_read_register_t)(void *handle, uint8_t addr, uint8_t *data, uint32_t len);
typedef mpu6500_ret_t (*mpu6500_ops_write_register_t)(void *handle, uint8_t addr, uint8_t *data, uint32_t len);
typedef mpu6500_ret_t (*mpu6500_ops_delay)(void *handle, uint32_t msec);
typedef struct {
mpu6500_ops_read_register_t read_register;
mpu6500_ops_write_register_t write_register;
mpu6500_ops_delay delay;
} mpu6500_ops_t;
typedef struct {
mpu6500_ops_t ops;
void *user_data;
} mpu6500_t;
mpu6500_ret_t mpu6500_init(mpu6500_t *mpu);
mpu6500_ret_t mpu6500_read_channel(mpu6500_t *mpu, mpu6500_channel_t ch, int16_t *result);
mpu6500_ret_t mpu6500_read_result(mpu6500_t *mpu, mpu6500_result_t *result);
mpu6500_ret_t mpu6500_get_accel_fullscale(mpu6500_t *mpu, uint16_t *f_scale);
mpu6500_ret_t mpu6500_get_gyro_fullscale(mpu6500_t *mpu, uint16_t *f_scale);
#endif