Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
imu_functions.h
Go to the documentation of this file.
1 
10 #ifndef IMU_FUNCTIONS_H_INCLUDED
11 #define IMU_FUNCTIONS_H_INCLUDED
12 
13 #include <stdio.h>
14 #include <stdint.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <errno.h>
18 #include <unistd.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <sys/ioctl.h>
22 #include <fcntl.h>
23 #include <linux/i2c-dev.h>
24 
25 #include "imu_regs.h"
26 
27 #define ASCII_0 0x30
28 
29 #define SUCCESS 1
30 #define FAILURE -1
31 
36 #define ADD_ADXL345 0x53
37 #define ADD_ITG3200 0x68
38 #define ADD_HMC5883 0x1E
39 
41 // FUNCTIONS FOR //
42 // ACCELEROMETER //
43 // ADXL345 //
45 
59 int acc_write_reg(int i2c_dev, uint8_t reg, uint8_t data);
60 
70 uint8_t* acc_read_reg(int i2c_dev, uint8_t reg, uint8_t count);
71 
89 int acc_init(int i2c_dev, uint8_t full_res, uint16_t rate, uint8_t range);
90 
99 int acc_read_all_data(int i2c_dev, short int *data);
100 
109 short int acc_read_data(int i2c_dev, int axis);
110 
111 char* conv_byte_hex_bin(uint8_t* hvalue);
112 
118 int acc_read_all_reg(int i2c_dev);
119 
121 // FUNCTIONS FOR //
122 // GYROMETER //
123 // ITG3200 //
125 
138 int gyr_write_reg(int i2c_dev, uint8_t reg, uint8_t data);
139 
148 uint8_t* gyr_read_reg(int i2c_dev, uint8_t reg, uint8_t count);
149 
179 int gyr_init(int i2c_dev, float rate, short int lpf_bw, char clk_source, char *act);
180 
188 int gyr_read_all_data(int i2c_dev, short int *data);
189 
198 short int gyr_read_data(int i2c_dev, int type);
199 
201 // FUNCTIONS FOR //
202 // MAGNETOMETER //
203 // HMC5883 //
205 
218 int mag_write_reg(int i2c_dev, uint8_t reg, uint8_t data);
219 
227 uint8_t* mag_read_reg(int i2c_dev, uint8_t reg, uint8_t count);
228 
232 int mag_init(int i2c_dev, uint8_t rate, uint8_t range, uint8_t samples_avg, uint8_t meas_mode, uint8_t op_mode);
233 /* Parameters
234 - rate (data output rate in Hz) = 3, 15, 30, 75
235 0: 0.75Hz
236 1: 1.5Hz
237 7: 7.5Hz
238 - samples_avg (number of sampled averaged per measurement output) = 1, 2, 4, 8
239 - meas_mode (measurement mode):
240 0: Normal measurement configuration. The device follows normal measurement flow.
241  The positive and negative pins of the resistive load are left floating and high impedance
242 1: Positive bias configuration for X, Y, and Z axes. In this configuration, a positive current
243  is forced across the resistive load for all three axes
244 2: Negative bias configuration for X, Y, and Z axes. In this configuration, a negative current
245  is forced across the resistive load for all three axes
246 - range:
247  Range (Ga) Resolution (mG/LSb)
248 0: +- 0.88 0.73
249 1: +- 1.3 0.92
250 2: +- 1.9 1.22
251 3: +- 2.5 1.52
252 4: +- 4.0 2.27
253 5: +- 4.7 2.56
254 6: +- 5.6 3.03
255 7: +- 8.1 4.35
256 */
257 
264 int mag_read_all_data(int i2c_dev, short int *data);
265 
272 short int mag_read_data(int i2c_dev, int axis);
273 
274 #endif
int acc_write_reg(int i2c_dev, uint8_t reg, uint8_t data)
WRITE TO REGISTER.
Definition: acc_functions.c:87
short int mag_read_data(int i2c_dev, int axis)
READ DATA (X, Y or Z)
short int gyr_read_data(int i2c_dev, int type)
READ DATA (X, Y, Z or T)
int gyr_write_reg(int i2c_dev, uint8_t reg, uint8_t data)
WRITE TO REGISTER.
Definition: gyr_functions.c:10
int mag_write_reg(int i2c_dev, uint8_t reg, uint8_t data)
WRITE TO REGISTER.
Definition: mag_functions.c:10
int acc_read_all_data(int i2c_dev, short int *data)
READ ALL DATA AT ONCE (X, Y and Z)
uint8_t * acc_read_reg(int i2c_dev, uint8_t reg, uint8_t count)
READ COUNT 8-BIT REGISTER IN SEQUENCE
uint8_t * mag_read_reg(int i2c_dev, uint8_t reg, uint8_t count)
READ COUNT 8-BIT REGISTER IN SEQUENCE.
Definition: mag_functions.c:31
uint8_t * gyr_read_reg(int i2c_dev, uint8_t reg, uint8_t count)
READ COUNT 8-BIT REGISTER IN SEQUENCE.
Definition: gyr_functions.c:31
short int acc_read_data(int i2c_dev, int axis)
READ DATA (X, Y or Z)
int acc_read_all_reg(int i2c_dev)
Read all accelerometer data and print in stdio.
int mag_init(int i2c_dev, uint8_t rate, uint8_t range, uint8_t samples_avg, uint8_t meas_mode, uint8_t op_mode)
INITIALIZE MAGNETOMETER.
Definition: mag_functions.c:53
int gyr_init(int i2c_dev, float rate, short int lpf_bw, char clk_source, char *act)
INITIALIZE GYROMETER.
Definition: gyr_functions.c:53
Registers that are present in each device from the IMU (ADXL345, ITG3200 and HMC5883) ...
int gyr_read_all_data(int i2c_dev, short int *data)
READ ALL DATA AT ONCE (X, Y, Z and T)
int mag_read_all_data(int i2c_dev, short int *data)
READ ALL DATA AT ONCE (X, Y and Z)
char * conv_byte_hex_bin(uint8_t *hvalue)
int acc_init(int i2c_dev, uint8_t full_res, uint16_t rate, uint8_t range)
INITIALIZE ACCELEROMETER.
Definition: acc_functions.c:11