Subversion Repositories Code-Repo

Rev

Rev 159 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
159 Kevin 1
#ifndef ACCEL_LSM303_H
2
#define	ACCEL_LSM303_H
3
 
4
// Device
5
#define LSM303DLH_DEVICE   0
6
#define LSM303DLM_DEVICE   1
7
#define LSM303DLHC_DEVICE  2
8
 
9
// SA0_A States
10
#define LSM303_SA0_A_LOW  0
11
#define LSM303_SA0_A_HIGH 1
12
 
13
// Slave Addresses
14
#define MAG_ADDRESS            (0x3C >> 1)
15
#define ACC_ADDRESS_SA0_A_LOW  (0x30 >> 1)
16
#define ACC_ADDRESS_SA0_A_HIGH (0x32 >> 1)
17
 
18
// Register Addresses
19
#define LSM303_CTRL_REG1_A       0x20
20
#define LSM303_CTRL_REG2_A       0x21
21
#define LSM303_CTRL_REG3_A       0x22
22
#define LSM303_CTRL_REG4_A       0x23
23
#define LSM303_CTRL_REG5_A       0x24
24
#define LSM303_CTRL_REG6_A       0x25 // DLHC only
25
#define LSM303_HP_FILTER_RESET_A 0x25 // DLH, DLM only
26
#define LSM303_REFERENCE_A       0x26
27
#define LSM303_STATUS_REG_A      0x27
28
 
29
#define LSM303_OUT_X_L_A         0x28
30
#define LSM303_OUT_X_H_A         0x29
31
#define LSM303_OUT_Y_L_A         0x2A
32
#define LSM303_OUT_Y_H_A         0x2B
33
#define LSM303_OUT_Z_L_A         0x2C
34
#define LSM303_OUT_Z_H_A         0x2D
35
 
36
#define LSM303_FIFO_CTRL_REG_A   0x2E // DLHC only
37
#define LSM303_FIFO_SRC_REG_A    0x2F // DLHC only
38
 
39
#define LSM303_INT1_CFG_A        0x30
40
#define LSM303_INT1_SRC_A        0x31
41
#define LSM303_INT1_THS_A        0x32
42
#define LSM303_INT1_DURATION_A   0x33
43
#define LSM303_INT2_CFG_A        0x34
44
#define LSM303_INT2_SRC_A        0x35
45
#define LSM303_INT2_THS_A        0x36
46
#define LSM303_INT2_DURATION_A   0x37
47
 
48
#define LSM303_CLICK_CFG_A       0x38 // DLHC only
49
#define LSM303_CLICK_SRC_A       0x39 // DLHC only
50
#define LSM303_CLICK_THS_A       0x3A // DLHC only
51
#define LSM303_TIME_LIMIT_A      0x3B // DLHC only
52
#define LSM303_TIME_LATENCY_A    0x3C // DLHC only
53
#define LSM303_TIME_WINDOW_A     0x3D // DLHC only
54
 
55
#define LSM303_CRA_REG_M         0x00
56
#define LSM303_CRB_REG_M         0x01
57
#define LSM303_MR_REG_M          0x02
58
 
59
#define LSM303_OUT_X_H_M         0x03
60
#define LSM303_OUT_X_L_M         0x04
61
#define LSM303_OUT_Y_H_M         -1   // The addresses of the Y and Z magnetometer output registers
62
#define LSM303_OUT_Y_L_M         -2   // are reversed on the DLM and DLHC relative to the DLH.
63
#define LSM303_OUT_Z_H_M         -3   // These four defines have dummy values so the library can
64
#define LSM303_OUT_Z_L_M         -4   // determine the correct address based on the device type.
65
 
66
#define LSM303_SR_REG_M          0x09
67
#define LSM303_IRA_REG_M         0x0A
68
#define LSM303_IRB_REG_M         0x0B
69
#define LSM303_IRC_REG_M         0x0C
70
 
71
#define LSM303_WHO_AM_I_M        0x0F // DLM only
72
 
73
#define LSM303_TEMP_OUT_H_M      0x31 // DLHC only
74
#define LSM303_TEMP_OUT_L_M      0x32 // DLHC only
75
 
76
#define LSM303DLH_OUT_Y_H_M      0x05
77
#define LSM303DLH_OUT_Y_L_M      0x06
78
#define LSM303DLH_OUT_Z_H_M      0x07
79
#define LSM303DLH_OUT_Z_L_M      0x08
80
 
81
#define LSM303DLM_OUT_Z_H_M      0x05
82
#define LSM303DLM_OUT_Z_L_M      0x06
83
#define LSM303DLM_OUT_Y_H_M      0x07
84
#define LSM303DLM_OUT_Y_L_M      0x08
85
 
86
#define LSM303DLHC_OUT_Z_H_M     0x05
87
#define LSM303DLHC_OUT_Z_L_M     0x06
88
#define LSM303DLHC_OUT_Y_H_M     0x07
89
#define LSM303DLHC_OUT_Y_L_M     0x08
90
 
91
typedef struct {
92
    char acc_address;
93
    char mag_address;
94
    char device;
95
} LSM303_DATA;
96
 
97
enum magGain {
98
    magGain_13 = 0x20, magGain_19 = 0x40,
99
    magGain_25 = 0x60, magGain_40 = 0x80,
100
    magGain_47 = 0xA0, magGain_56 = 0xC0,
101
    magGain_81 = 0xE0
102
};
103
 
104
void LSM303_Init(LSM303_DATA *data, char device, char sa0);
105
void LSM303_Begin(void);
106
 
107
void LSM303_Write_A_Reg(char reg, char value);
108
void LSM303_Write_M_Reg(char reg, char value);
109
 
110
void LSM303_Set_Mag_Gain(enum magGain value);
111
 
112
void LSM303_Read_Acc(int *x, int *y, int *z);
113
void LSM303_Read_Mag(int *x, int *y, int *z);
114
 
115
#endif
116