//IMUIIM.h

#ifndef IMUIIM_H
#define	IMUIIM_H

#define IIM_Register_Bank_Sel 0x76 //select register bank
//In bank 0:
#define IIM_Device_Config 0x011
#define IIM_Int_Config 0x014
#define IIM_Temp_Data_1 0x01D
#define IIM_Temp_Data_0 0x01E
#define IIM_Acc_Data_X_1 0x01F
#define IIM_Acc_Data_X_0 0x020
#define IIM_Acc_Data_Y_1 0x021
#define IIM_Acc_Data_Y_0 0x022
#define IIM_Acc_Data_Z_1 0x023
#define IIM_Acc_Data_Z_0 0x024
#define IIM_Gyro_Data_X_1 0x025
#define IIM_Gyro_Data_X_0 0x026
#define IIM_Gyro_Data_Y_1 0x027
#define IIM_Gyro_Data_Y_0 0x028
#define IIM_Gyro_Data_Z_1 0x029
#define IIM_Gyro_Data_Z_0 0x02A
#define IIM_Int_Status 0x02D
#define IIM_FIFO_Data 0x030
#define IIM_Int_Status_3 0x038
#define IIM_Signal_Path_Reset 0x04B
#define IIM_Intf_Config_0 0x04C
#define IIM_Intf_Config_1 0x04D
#define IIM_Power_Management_0 0x04E
#define IIM_Gyro_Config_0 0x04F
#define IIM_Acc_Config_0 0x050
#define IIM_Gyro_Config_1 0x051
#define IIM_GyroAcc_Config_0 0x052
#define IIM_Acc_Config_1 0x053
#define IIM_APEX_Config_0 0x056
#define IIM_FIFO_Config_1 0x05F
#define IIM_FIFO_Config_2 0x060
#define IIM_FIFO_Config_3 0x061
#define IIM_FSYNC_Config 0x062
#define IIM_Int_Config_0 0x063
#define IIM_Int_Config_1 0x064
#define IIM_Int_Source_0 0x065
#define IIM_Int_Source_1 0x066
#define IIM_Int_Source_3 0x068
#define IIM_Int_Source_4 0x069
#define IIM_FIFO_Lost_Packet_0 0x06C
#define IIM_FIFO_Lost_Packet_1 0x06D
#define IIM_Self_Test_Config 0x070
//In bank 1:
#define IIM_Sensor_Config_0 0x103
#define IIM_Gyro_Config_Static_2 0x10B
#define IIM_Gyro_Config_Static_3 0x10C
#define IIM_Gyro_Config_Static_4 0x10D
#define IIM_Gyro_Config_Static_5 0x10E
#define IIM_Gyro_Config_Static_6 0x10F
#define IIM_Gyro_Config_Static_7 0x110
#define IIM_Gyro_Config_Static_8 0x111
#define IIM_Gyro_Config_Static_9 0x112
#define IIM_Gyro_Config_Static_10 0x113
#define IIM_Gyro_Self_Test_Data_X 0x15F
#define IIM_Gyro_Self_Test_Data_Y 0x160
#define IIM_Gyro_Self_Test_Data_Z 0x161
#define IIM_INTF_Config_4 0x17A
#define IIM_INTF_Config_5 0x17B
//In bank 2:
#define IIM_Acc_Config_Static_2 0x203
#define IIM_Acc_Config_Static_3 0x204
#define IIM_Acc_Config_Static_4 0x205
#define IIM_Acc_Self_Test_Data_X 0x23B
#define IIM_Acc_Self_Test_Data_Y 0x23C
#define IIM_Acc_Self_Test_Data_Z 0x23D
//In bank 3:
#define IIM_PullUD_Config_1 0x306
#define IIM_PullUD_Config_2 0x30E
//In bank 4:
#define IIM_FIFO_Decimator_Factor_Config 0x409
#define IIM_APEX_Config_4 0x443
#define IIM_Int_Source_6 0x44D
#define IIM_Int_Source_7 0x44E
#define IIM_Gyro_X_L_Offset_Set 0x477
#define IIM_Gyro_XY_H_Offset_Set 0x478
#define IIM_Gyro_Y_L_Offset_Set 0x479
#define IIM_Gyro_Z_L_Offset_Set 0x47A
#define IIM_Acc_X_H_Gyro_Z_H_Offset_Set 0x47B
#define IIM_Acc_X_L_Offset_Set 0x47C
#define IIM_Acc_Y_L_Offset_Set 0x47D
#define IIM_Acc_YZ_H_Offset_Set 0x47E
#define IIM_Acc_Z_L_Offset_Set 0x47F

typedef struct IIM_DATA{
    float iim_temp;
    float iim_acc_x;
    float iim_acc_y;
    float iim_acc_z;
    float iim_gyro_x;
    float iim_gyro_y;
    float iim_gyro_z;
}IIM_DATA;

typedef struct {
    int16_t x;
    int16_t y;
    int16_t z;
} _axesIIMInt;

uint8_t IIM_Read_Operation(uint8_t Reg_Name);
void IIM_Bank_Set(uint8_t IIM_Bank_Num);
void IIM_Reg_Set(uint16_t Reg_Name, uint8_t Reg_Name_Set);
void IIM_init(void);
void IIM_Calib(uint16_t loop);
void IIM_Meas_Tilt(void);
float IIM_Single_Meas_Tilt(void);
void IIM_Meas_Angle(void);
float IIM_Single_Meas_Filtered_Angle(void);
float IIM_Single_Meas_Drift_Angle(void);
void IIM_Drift_Error(int8_t error_x, int8_t error_y, int8_t error_z);
void IIM_Meas_Raw(uint16_t loop);
void IIM_Meas_Compensated(uint16_t loop);
void IIM_Separate_Data(uint8_t *data);
float IIM_Read_Data(uint16_t Reg_Name, uint8_t Byte_Count);
void IIM_Get_Float_Data(IIM_DATA *data);

#endif	/* IMUIIM_H */

