156 lines
3 KiB
C
156 lines
3 KiB
C
/*
|
|
* Author: Jake Goodwin
|
|
* Date: 2023
|
|
* Description: A Generic driver for gy521 IMU modules
|
|
*/
|
|
|
|
#ifndef GY521_DRIVER_H
|
|
#define GY521_DRIVER_H
|
|
#include "gy521_interface.h"
|
|
#include <stdlib.h>
|
|
|
|
/*
|
|
* ############################
|
|
* Defines
|
|
* ############################
|
|
*/
|
|
|
|
/*
|
|
* ############################
|
|
* Types/Structures
|
|
* ############################
|
|
*/
|
|
|
|
typedef struct gyro_values{
|
|
uint16_t x;
|
|
uint16_t y;
|
|
uint16_t z;
|
|
}gyro_values_struct;
|
|
|
|
typedef struct accel_values{
|
|
uint16_t x;
|
|
uint16_t y;
|
|
uint16_t z;
|
|
}accel_values_struct;
|
|
|
|
/*
|
|
* ############################
|
|
* REGISTER MAP
|
|
* ############################
|
|
*/
|
|
|
|
/*This thing is fairly huge, but it's got pretty much all the registers
|
|
* on it.*/
|
|
|
|
enum gy521_map {
|
|
self_test_x = 0x0D,
|
|
self_test_y,
|
|
self_test_z,
|
|
self_test_a,
|
|
smplrt_div = 0x19,
|
|
config,
|
|
gyro_config,
|
|
accel_config,
|
|
fifo_en = 0x23,
|
|
i2c_mst_ctrl,
|
|
i2c_slv0_addr,
|
|
i2c_slv0_reg,
|
|
i2c_slv0_ctrl,
|
|
i2c_slv1_addr,
|
|
i2c_slv1_reg,
|
|
i2c_slv1_ctrl,
|
|
i2c_slv2_addr,
|
|
i2c_slv2_reg,
|
|
i2c_slv2_ctrl,
|
|
i2c_slv3_addr,
|
|
i2c_slv3_reg,
|
|
i2c_slv3_ctrl,
|
|
i2c_slv4_addr,
|
|
i2c_slv4_reg,
|
|
i2c_slv4_do,
|
|
i2c_slv4_ctrl,
|
|
i2c_slv4_di,
|
|
i2c_mst_status,
|
|
int_pin_cfg,
|
|
int_enable,
|
|
int_status,
|
|
accel_xouth = 0x3B,
|
|
accel_xoutl,
|
|
accel_youth,
|
|
accel_youtl,
|
|
accel_zouth,
|
|
accel_zoutl,
|
|
temp_outh,
|
|
temp_outl,
|
|
gyro_xouth,
|
|
gyro_xoutl,
|
|
gyro_youth,
|
|
gyro_youtl,
|
|
gyro_zouth,
|
|
gyro_zoutl,
|
|
ext_sens_data_00,
|
|
ext_sens_data_01,
|
|
ext_sens_data_02,
|
|
ext_sens_data_03,
|
|
ext_sens_data_04,
|
|
ext_sens_data_05,
|
|
ext_sens_data_06,
|
|
ext_sens_data_07,
|
|
ext_sens_data_08,
|
|
ext_sens_data_09,
|
|
ext_sens_data_10,
|
|
ext_sens_data_11,
|
|
ext_sens_data_12,
|
|
ext_sens_data_13,
|
|
ext_sens_data_14,
|
|
ext_sens_data_15,
|
|
ext_sens_data_16,
|
|
ext_sens_data_17,
|
|
ext_sens_data_18,
|
|
ext_sens_data_19,
|
|
ext_sens_data_20,
|
|
ext_sens_data_21,
|
|
ext_sens_data_22,
|
|
ext_sens_data_23,
|
|
i2c_slv0_do,
|
|
i2c_slv1_do,
|
|
i2c_slv2_do,
|
|
i2c_slv3_do,
|
|
i2c_mst_delay_ctrl,
|
|
signal_path_reset,
|
|
user_ctrl,
|
|
pwr_mgmt_1,
|
|
pwr_mgmt_2,
|
|
fifo_couth = 0x72,
|
|
fifo_contl,
|
|
fifo_r_w,
|
|
who_am_i,
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
* ############################
|
|
* Function Prototypes
|
|
* ############################
|
|
*/
|
|
|
|
gy521_module* gy521_new(void);
|
|
|
|
void disable_self_test_gyro(struct gy521_module* m);
|
|
void enable_self_test_gyro(struct gy521_module* m);
|
|
struct ft_vals self_test_ft_calculation(struct gy521_module* m);
|
|
self_test_results gy521_self_test(struct gy521_module* m);
|
|
|
|
uint8_t read_register(gy521_module *m, enum gy521_map reg);
|
|
void write_register(gy521_module *m, enum gy521_map reg, uint8_t data);
|
|
|
|
|
|
/*These are used instead of direct access; assuming interrupt driven*/
|
|
/*updates to the gy521 then it protects the user from using volatile values*/
|
|
struct accel_values gy521_get_accel(struct gy521_module* m);
|
|
struct gyro_values gy521_get_gyro(struct gy521_module* m);
|
|
|
|
|
|
|
|
#endif /* GY521_DRIVER_H */
|