Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/drivers/ADXL345/ADXL345.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ADXL345.h
3 * @brief Header file of ADXL345 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2012(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 ********************************************************************************
40 * SVN Revision: $WCREV$
41 *******************************************************************************/
42 #ifndef __ADXL345_H__
43 #define __ADXL345_H__
44
45 /******************************************************************************/
46 /******************************** ADXL345 *************************************/
47 /******************************************************************************/
48
49 /* Options for communicating with the device. */
50 #define ADXL345_SPI_COMM 0
51 #define ADXL345_I2C_COMM 1
52
53 /* SPI slave device ID */
54 #define ADXL345_SLAVE_ID 1
55
56 /* I2C address of the device */
57 #define ADXL345_ADDRESS 0x1D
58
59 /* SPI commands */
60 #define ADXL345_SPI_READ (1 << 7)
61 #define ADXL345_SPI_WRITE (0 << 7)
62 #define ADXL345_SPI_MB (1 << 6)
63
64 /* ADXL345 Register Map */
65 #define ADXL345_DEVID 0x00 // R Device ID.
66 #define ADXL345_THRESH_TAP 0x1D // R/W Tap threshold.
67 #define ADXL345_OFSX 0x1E // R/W X-axis offset.
68 #define ADXL345_OFSY 0x1F // R/W Y-axis offset.
69 #define ADXL345_OFSZ 0x20 // R/W Z-axis offset.
70 #define ADXL345_DUR 0x21 // R/W Tap duration.
71 #define ADXL345_LATENT 0x22 // R/W Tap latency.
72 #define ADXL345_WINDOW 0x23 // R/W Tap window.
73 #define ADXL345_THRESH_ACT 0x24 // R/W Activity threshold.
74 #define ADXL345_THRESH_INACT 0x25 // R/W Inactivity threshold.
75 #define ADXL345_TIME_INACT 0x26 // R/W Inactivity time.
76 #define ADXL345_ACT_INACT_CTL 0x27 // R/W Axis enable control for activity
77 // and inactivity detection.
78 #define ADXL345_THRESH_FF 0x28 // R/W Free-fall threshold.
79 #define ADXL345_TIME_FF 0x29 // R/W Free-fall time.
80 #define ADXL345_TAP_AXES 0x2A // R/W Axis control for tap/double tap.
81 #define ADXL345_ACT_TAP_STATUS 0x2B // R Source of tap/double tap.
82 #define ADXL345_BW_RATE 0x2C // R/W Data rate and power mode control.
83 #define ADXL345_POWER_CTL 0x2D // R/W Power saving features control.
84 #define ADXL345_INT_ENABLE 0x2E // R/W Interrupt enable control.
85 #define ADXL345_INT_MAP 0x2F // R/W Interrupt mapping control.
86 #define ADXL345_INT_SOURCE 0x30 // R Source of interrupts.
87 #define ADXL345_DATA_FORMAT 0x31 // R/W Data format control.
88 #define ADXL345_DATAX0 0x32 // R X-Axis Data 0.
89 #define ADXL345_DATAX1 0x33 // R X-Axis Data 1.
90 #define ADXL345_DATAY0 0x34 // R Y-Axis Data 0.
91 #define ADXL345_DATAY1 0x35 // R Y-Axis Data 1.
92 #define ADXL345_DATAZ0 0x36 // R Z-Axis Data 0.
93 #define ADXL345_DATAZ1 0x37 // R Z-Axis Data 1.
94 #define ADXL345_FIFO_CTL 0x38 // R/W FIFO control.
95 #define ADXL345_FIFO_STATUS 0x39 // R FIFO status.
96
97 /* ADXL345_ACT_INACT_CTL definition */
98 #define ADXL345_ACT_ACDC (1 << 7)
99 #define ADXL345_ACT_X_EN (1 << 6)
100 #define ADXL345_ACT_Y_EN (1 << 5)
101 #define ADXL345_ACT_Z_EN (1 << 4)
102 #define ADXL345_INACT_ACDC (1 << 3)
103 #define ADXL345_INACT_X_EN (1 << 2)
104 #define ADXL345_INACT_Y_EN (1 << 1)
105 #define ADXL345_INACT_Z_EN (1 << 0)
106
107 /* ADXL345_TAP_AXES definition */
108 #define ADXL345_SUPPRESS (1 << 3)
109 #define ADXL345_TAP_X_EN (1 << 2)
110 #define ADXL345_TAP_Y_EN (1 << 1)
111 #define ADXL345_TAP_Z_EN (1 << 0)
112
113 /* ADXL345_ACT_TAP_STATUS definition */
114 #define ADXL345_ACT_X_SRC (1 << 6)
115 #define ADXL345_ACT_Y_SRC (1 << 5)
116 #define ADXL345_ACT_Z_SRC (1 << 4)
117 #define ADXL345_ASLEEP (1 << 3)
118 #define ADXL345_TAP_X_SRC (1 << 2)
119 #define ADXL345_TAP_Y_SRC (1 << 1)
120 #define ADXL345_TAP_Z_SRC (1 << 0)
121
122 /* ADXL345_BW_RATE definition */
123 #define ADXL345_LOW_POWER (1 << 4)
124 #define ADXL345_RATE(x) ((x) & 0xF)
125
126 /* ADXL345_POWER_CTL definition */
127 #define ADXL345_PCTL_LINK (1 << 5)
128 #define ADXL345_PCTL_AUTO_SLEEP (1 << 4)
129 #define ADXL345_PCTL_MEASURE (1 << 3)
130 #define ADXL345_PCTL_SLEEP (1 << 2)
131 #define ADXL345_PCTL_WAKEUP(x) ((x) & 0x3)
132
133 /* ADXL345_INT_ENABLE / ADXL345_INT_MAP / ADXL345_INT_SOURCE definition */
134 #define ADXL345_DATA_READY (1 << 7)
135 #define ADXL345_SINGLE_TAP (1 << 6)
136 #define ADXL345_DOUBLE_TAP (1 << 5)
137 #define ADXL345_ACTIVITY (1 << 4)
138 #define ADXL345_INACTIVITY (1 << 3)
139 #define ADXL345_FREE_FALL (1 << 2)
140 #define ADXL345_WATERMARK (1 << 1)
141 #define ADXL345_OVERRUN (1 << 0)
142
143 /* ADXL345_DATA_FORMAT definition */
144 #define ADXL345_SELF_TEST (1 << 7)
145 #define ADXL345_SPI (1 << 6)
146 #define ADXL345_INT_INVERT (1 << 5)
147 #define ADXL345_FULL_RES (1 << 3)
148 #define ADXL345_JUSTIFY (1 << 2)
149 #define ADXL345_RANGE(x) ((x) & 0x3)
150
151 /* ADXL345_RANGE(x) options */
152 #define ADXL345_RANGE_PM_2G 0
153 #define ADXL345_RANGE_PM_4G 1
154 #define ADXL345_RANGE_PM_8G 2
155 #define ADXL345_RANGE_PM_16G 3
156
157 /* ADXL345_FIFO_CTL definition */
158 #define ADXL345_FIFO_MODE(x) (((x) & 0x3) << 6)
159 #define ADXL345_TRIGGER (1 << 5)
160 #define ADXL345_SAMPLES(x) ((x) & 0x1F)
161
162 /* ADXL345_FIFO_MODE(x) options */
163 #define ADXL345_FIFO_BYPASS 0
164 #define ADXL345_FIFO_FIFO 1
165 #define ADXL345_FIFO_STREAM 2
166 #define ADXL345_FIFO_TRIGGER 3
167
168 /* ADXL345_FIFO_STATUS definition */
169 #define ADXL345_FIFO_TRIG (1 << 7)
170 #define ADXL345_ENTRIES(x) ((x) & 0x3F)
171
172 /* ADXL345 ID */
173 #define ADXL345_ID 0xE5
174
175 /* ADXL345 Full Resolution Scale Factor */
176 #define ADXL345_SCALE_FACTOR 0.0039
177
178 /******************************************************************************/
179 /************************ Functions Declarations ******************************/
180 /******************************************************************************/
181
182 /*! Reads the value of a register. */
183 unsigned char ADXL345_GetRegisterValue(unsigned char registerAddress);
184
185 /*! Writes data into a register. */
186 void ADXL345_SetRegisterValue(unsigned char registerAddress,
187 unsigned char registerValue);
188
189 /*! Init. the comm. peripheral and checks if the ADXL345 part is present. */
190 char ADXL345_Init(char commProtocol);
191
192 /*! Places the device into standby/measure mode. */
193 void ADXL345_SetPowerMode(unsigned char pwrMode);
194
195 /*! Reads the raw output data of each axis. */
196 void ADXL345_GetXyz(short* x,
197 short* y,
198 short* z);
199
200 /*! Reads the raw output data of each axis and converts it to g. */
201 void ADXL345_GetGxyz(float* x,
202 float* y,
203 float* z);
204
205 /*! Enables/disables the tap detection. */
206 void ADXL345_SetTapDetection(unsigned char tapType,
207 unsigned char tapAxes,
208 unsigned char tapDur,
209 unsigned char tapLatent,
210 unsigned char tapWindow,
211 unsigned char tapThresh,
212 unsigned char tapInt);
213
214 /*! Enables/disables the activity detection. */
215 void ADXL345_SetActivityDetection(unsigned char actOnOff,
216 unsigned char actAxes,
217 unsigned char actAcDc,
218 unsigned char actThresh,
219 unsigned char actInt);
220
221 /*! Enables/disables the inactivity detection. */
222 void ADXL345_SetInactivityDetection(unsigned char inactOnOff,
223 unsigned char inactAxes,
224 unsigned char inactAcDc,
225 unsigned char inactThresh,
226 unsigned char inactTime,
227 unsigned char inactInt);
228
229 /*! Enables/disables the free-fall detection. */
230 void ADXL345_SetFreeFallDetection(unsigned char ffOnOff,
231 unsigned char ffThresh,
232 unsigned char ffTime,
233 unsigned char ffInt);
234
235 /*! Sets an offset value for each axis (Offset Calibration). */
236 void ADXL345_SetOffset(unsigned char xOffset,
237 unsigned char yOffset,
238 unsigned char zOffset);
239
240 /*! Selects the measurement range. */
241 void ADXL345_SetRangeResolution(unsigned char gRange, unsigned char fullRes);
242
243 #endif /* __ADXL345_H__ */