| 1 | /***************************************************************************//** |
| 2 | * @file ADXL345.h |
| 3 | * @brief Header file of ADXL345 Driver. |
| 4 | * @author ATofan ([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 | #include "xparameters.h" |
| 46 | #include "xil_cache.h" |
| 47 | #include "xil_io.h" |
| 48 | |
| 49 | /******************************************************************************/ |
| 50 | /* ADXL345 */ |
| 51 | /******************************************************************************/ |
| 52 | #define ADXL345_RnW 7 |
| 53 | #define ADXL345_MB 6 |
| 54 | // ADXL345 Registers |
| 55 | #define ADXL345_DEVID 0x00 |
| 56 | #define ADXL345_THRESH_TAP 0x1D |
| 57 | #define ADXL345_OFSX 0x1E |
| 58 | #define ADXL345_OFSY 0x1F |
| 59 | #define ADXL345_OFSZ 0x20 |
| 60 | #define ADXL345_DUR 0x21 |
| 61 | #define ADXL345_Latent 0x22 |
| 62 | #define ADXL345_Window 0x23 |
| 63 | #define ADXL345_THRESH_ACT 0x24 |
| 64 | #define ADXL345_THRESH_INACT 0x25 |
| 65 | #define ADXL345_TIME_INACT 0x26 |
| 66 | #define ADXL345_ACT_INACT_CTL 0x27 |
| 67 | #define ADXL345_THRESH_FF 0x28 |
| 68 | #define ADXL345_TIME_FF 0x29 |
| 69 | #define ADXL345_TAP_AXES 0x2A |
| 70 | #define ADXL345_ACT_TAP_STATUS 0x2B |
| 71 | #define ADXL345_BW_RATE 0x2C |
| 72 | #define ADXL345_POWER_CTL 0x2D |
| 73 | #define ADXL345_INT_ENABLE 0x2E |
| 74 | #define ADXL345_INT_MAP 0x2F |
| 75 | #define ADXL345_INT_SOURCE 0x30 |
| 76 | #define ADXL345_DATA_FORMAT 0x31 |
| 77 | #define ADXL345_DATA_X0 0x32 |
| 78 | #define ADXL345_DATA_X1 0x33 |
| 79 | #define ADXL345_DATA_Y0 0x34 |
| 80 | #define ADXL345_DATA_Y1 0x35 |
| 81 | #define ADXL345_DATA_Z0 0x36 |
| 82 | #define ADXL345_DATA_Z1 0x37 |
| 83 | #define ADXL345_FIFO_CTL 0x38 |
| 84 | #define ADXL345_FIFO_STATUS 0x39 |
| 85 | |
| 86 | // Register specific bits |
| 87 | // Device ID Register 0x00 - Read value should be 0xE5 |
| 88 | // Tap Threshold Register 0x1D - Holds Threshold values for tap interrupts |
| 89 | // Offset X Register 0x1E | |
| 90 | // Offset Y Register 0x1F |- 15.6 mg/LSB, added to the acceleration data |
| 91 | // Offset Z Register 0x20 | |
| 92 | // Tap Duration Register 0x21 - 625us/LSB. Holds time that an event must be above THRESH_TAP to qualify as event |
| 93 | // Latent Register 0x22 - Time from detection of tap to time window. 1.25ms/LSB |
| 94 | // Window Register 0x23 - Time when a second tap can be detected. 1.25ms/LSB |
| 95 | // Activity Threshold Register 0x24 - Threshold value for detecting activity. 62.5mg/LSB |
| 96 | // Inactivity Threshold Register 0x25 - Threshold value for detecting inactivity. 62.5mg/LSB |
| 97 | // Inactivity Time Register 0x26 - Time for which acceleration must be less than THRESH_INACT. 1s/LSB |
| 98 | // Activity/Inactivity Control Register 0x27 |
| 99 | #define ADXL345_ACT_ac_dc 7 |
| 100 | #define ADXL345_ACT_X_en 6 |
| 101 | #define ADXL345_ACT_Y_en 5 |
| 102 | #define ADXL345_ACT_Z_en 4 |
| 103 | #define ADXL345_INACT_ac_dc 3 |
| 104 | #define ADXL345_INACT_X_en 2 |
| 105 | #define ADXL345_INACT_Y_en 1 |
| 106 | #define ADXL345_INACT_Z_en 0 |
| 107 | // Threshold Free Fall Register 0x28 - Value for free fall detection. 62.5mg/LSB 0x05 to 0x09 are recommended |
| 108 | // Free Fall Time Register 0x29 - Time for which axes value must be lower than THRESH_FF to generate fall interrupt. 5ms/LSB. 0x14 to 0x46 recommended |
| 109 | // Axes Control For Single/Double Tap Register 0x2A |
| 110 | #define ADXL345_Suppress 3 |
| 111 | #define ADXL345_TAP_X_en 2 |
| 112 | #define ADXL345_TAP_Y_en 1 |
| 113 | #define ADXL345_TAP_Z_en 0 |
| 114 | // Source Of Single/Double Tap Register 0x2B |
| 115 | #define ADXL345_ACT_X_Source 6 |
| 116 | #define ADXL345_ACT_Y_Source 5 |
| 117 | #define ADXL345_ACT_Z_Source 4 |
| 118 | #define ADXL345_ASleep 3 |
| 119 | #define ADXL345_TAP_X_Source 2 |
| 120 | #define ADXL345_TAP_Y_Source 1 |
| 121 | #define ADXL345_TAP_Z_Source 0 |
| 122 | // Data Rate and Power Mode Control Register 0x2C |
| 123 | #define ADXL345_LOW_POWER 4 |
| 124 | #define ADXL345_RATE 0 |
| 125 | // Power Savings Features Control Register 0x2D |
| 126 | #define ADXL345_Link 5 |
| 127 | #define ADXL345_AUTO_SLEEP 4 |
| 128 | #define ADXL345_Measure 3 |
| 129 | #define ADXL345_Sleep 2 |
| 130 | #define ADXL345_Wakeup 0 |
| 131 | // Interrupt Enable Control Register 0x2E |
| 132 | // Interrupt Mapping Control Register 0x2F |
| 133 | // Interrupt Source Register 0x30 |
| 134 | #define ADXL345_DATA_READY 7 |
| 135 | #define ADXL345_SINGLE_TAP 6 |
| 136 | #define ADXL345_DOUBLE_TAP 5 |
| 137 | #define ADXL345_Activity 4 |
| 138 | #define ADXL345_Inactivity 3 |
| 139 | #define ADXL345_FREE_FALL 2 |
| 140 | #define ADXL345_Watermark 1 |
| 141 | #define ADXL345_Overrun 0 |
| 142 | // Data Format Control Register 0x31 |
| 143 | #define ADXL345_SELF_TEST 7 |
| 144 | #define ADXL345_SPI 6 |
| 145 | #define ADXL345_INT_INVERT 5 |
| 146 | #define ADXL345_FULL_RES 3 |
| 147 | #define ADXL345_Justify 2 |
| 148 | #define ADXL345_Range 0 |
| 149 | // X-Axis Data0 Register 0x32 |
| 150 | // X-Axis Data1 Register 0x33 |
| 151 | // Y-Axis Data0 Register 0x34 |
| 152 | // Y-Axis Data1 Register 0x35 |
| 153 | // Z-Axis Data0 Register 0x36 |
| 154 | // Z-Axis Data1 Register 0x37 |
| 155 | // FIFO Control Register 0x38 |
| 156 | #define ADXL345_FIFO_MODE 6 |
| 157 | #define ADXL345_Trigger 5 |
| 158 | #define ADXL345_Samples 0 |
| 159 | // FIFO Status Register 0x39 |
| 160 | #define ADXL345_FIFO_TRIG 7 |
| 161 | #define ADXL345_Entries 0 |
| 162 | |
| 163 | void ADXL345_DisplayMainMenu(void); |
| 164 | void ADXL345_DisplayMenu(void); |
| 165 | void ADXL345_DisplayRangeMenu(void); |
| 166 | void ADXL345_DisplayRateMenu(void); |
| 167 | void ADXL345_DisplayTapMenu(void); |
| 168 | void delay_ms(u32 ms_count); |
| 169 | void ADXL345_WriteReg(unsigned char addr, unsigned char txData); |
| 170 | int ADXL345_ReadReg(unsigned char addr); |
| 171 | int ADXL345_BurstReadReg(unsigned char addr); |
| 172 | void ADXL345_Init(void); |
| 173 | void ADXL345_Display_G_Force(char axis); |
| 174 | void ADXL345_DisplayAllAxes(void); |
| 175 | void ADXL345_ReadAllAxes(void); |
| 176 | void ADXL345_Run(void); |
| 177 | void ADXL345_Stop(void); |
| 178 | void ADXL345_DisplayAccel(void); |
| 179 | void ADXL345_SelectRange(void); |
| 180 | void ADXL345_AcquisitionRate(void); |
| 181 | void ADXL345_SelectTap(void); |
| 182 | void DemoProgram(void); |
| 183 | |
| 184 | |
| 185 | |
| 186 | #endif /* ADXL345_H_ */ |