ADXL362 accelerometer library
Dependents: BLENano_SimpleTemplate_adxl362_170813 nRF51_ADXL3xx
Fork of ADXL362 by
ADXL362.h
00001 #ifndef ADXL362_H_ 00002 #define ADXL362_H_ 00003 00004 /** 00005 * @file ADXL362.cpp 00006 * @brief Header file for ADXL362 00007 * @author Analog Devices Inc. 00008 * 00009 * For support please go to: 00010 * Github: https://github.com/analogdevicesinc/mbed-adi 00011 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers 00012 * Product: http://www.analog.com/adxl362 00013 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all 00014 00015 ******************************************************************************** 00016 * Copyright 2016(c) Analog Devices, Inc. 00017 * 00018 * All rights reserved. 00019 * 00020 * Redistribution and use in source and binary forms, with or without 00021 * modification, are permitted provided that the following conditions are met: 00022 * - Redistributions of source code must retain the above copyright 00023 * notice, this list of conditions and the following disclaimer. 00024 * - Redistributions in binary form must reproduce the above copyright 00025 * notice, this list of conditions and the following disclaimer in 00026 * the documentation and/or other materials provided with the 00027 * distribution. 00028 * - Neither the name of Analog Devices, Inc. nor the names of its 00029 * contributors may be used to endorse or promote products derived 00030 * from this software without specific prior written permission. 00031 * - The use of this software may or may not infringe the patent rights 00032 * of one or more patent holders. This license does not release you 00033 * from the requirement that you obtain separate licenses from these 00034 * patent holders to use this software. 00035 * - Use of the software either in source or binary form, must be run 00036 * on or directly connected to an Analog Devices Inc. component. 00037 * 00038 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00039 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00040 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00041 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00042 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00043 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00044 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00045 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00046 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00047 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00048 * 00049 ********************************************************************************/ 00050 00051 #include "mbed.h" 00052 00053 /** 00054 * @brief Analog devices ADXL362 Digital Output MEMS Accelerometer 00055 */ 00056 class ADXL362 00057 { 00058 public: 00059 00060 /* Temperature parameters */ 00061 typedef enum { 00062 DEVID_AD = 0x00, 00063 DEVID_MST = 0x01, 00064 PARTID = 0x02, 00065 REVID = 0x03, 00066 XDATA = 0x08, 00067 YDATA = 0x09, 00068 ZDATA = 0x0A, 00069 STATUS = 0x0B, 00070 FIFO_ENTRIES_L = 0x0C, 00071 FIFO_ENTRIES_H = 0x0D, 00072 XDATA_L = 0x0E, 00073 XDATA_H = 0x0F, 00074 YDATA_L = 0x10, 00075 YDATA_H = 0x11, 00076 ZDATA_L = 0x12, 00077 ZDATA_H = 0x13, 00078 TEMP_L = 0x14, 00079 TEMP_H = 0x15, 00080 // Reserved = 0x16; 00081 // Reserved = 0x17; 00082 SOFT_RESET = 0x1F, 00083 THRESH_ACT_L = 0x20, 00084 THRESH_ACT_H = 0x21, 00085 TIME_ACT = 0x22, 00086 THRESH_INACT_L = 0x23, 00087 THRESH_INACT_H = 0x24, 00088 TIME_INACT_L = 0x25, 00089 TIME_INACT_H = 0x26, 00090 ACT_INACT_CTL = 0x27, 00091 FIFO_CONTROL = 0x28, 00092 FIFO_SAMPLES = 0x29, 00093 INTMAP1 = 0x2A, 00094 INTMAP2 = 0x2B, 00095 FILTER_CTL = 0x2C, 00096 POWER_CTL = 0x2D, 00097 SELF_TEST = 0x2E, 00098 } ADXL362_register_t; 00099 00100 typedef enum { 00101 STANDBY = 0x00, 00102 MEASUREMENT = 0x02 00103 } ADXL362_modes_t; 00104 00105 typedef enum { 00106 ERR_USER_REGS = 0x80, 00107 AWAKE = 0x40, 00108 INACT = 0x20, 00109 ACT = 0x10, 00110 FIFO_OVERRUN = 0x08, 00111 FIFO_WATERMARK = 0x04, 00112 FIFO_READY = 0x02, 00113 DATA_READY = 0x01 00114 } ADXL362_STATUS_reg_bits_t; 00115 00116 typedef enum { 00117 LINKLOOP1 = 0x20, 00118 LINKLOOP0 = 0x10, 00119 DEFAULTMODE = 0x00, 00120 LINKED_MODE = 0x10, 00121 LOOP_MODE = 0x30, 00122 INACT_REF = 0x08, 00123 INACT_EN = 0x04, 00124 ACT_REF = 0x02, 00125 ACT_EN = 0x01 00126 } ADXL362_ACT_INACT_CTL_reg_bits_t; 00127 00128 typedef enum { 00129 AH = 0x08, 00130 FIFO_TEMP = 0x04, 00131 FIFO_MODE1 = 0x02, 00132 FIFO_MODE = 0x01, 00133 } ADXL362_FIFO_CONTROL_reg_bits_t; 00134 00135 typedef enum { 00136 FIFO_DISABLED = 0x00, 00137 FIFO_OLDEST = 0x01, 00138 FIFO_STREAM = 0x02, 00139 FIFO_TRIGGERED = 0x03, 00140 } ADXL362_FIFO_modes_t; 00141 00142 typedef enum { 00143 INT_LOW = 0x80, 00144 INT_AWAKE = 0x40, 00145 INT_INACT = 0x20, 00146 INT_ACT = 0x10, 00147 INT_FIFO_OVERRUN = 0x08, 00148 INT_FIFO_WATERMARK = 0x04, 00149 INT_FIFO_READY = 0x02, 00150 INT_DATA_READY = 0x01 00151 } ADXL362_INTMAP_reg_bits_t; 00152 00153 typedef enum { 00154 RANGE1 = 0x80, 00155 RANGE0 = 0x40, 00156 RANGE2G = 0x00, 00157 RANGE4G = 0x40, 00158 RANGE8G = 0x80, 00159 HALF_BW = 0x10, 00160 EXT_SAMPLE = 0x08, 00161 ODR2 = 0x04, 00162 ODR1 = 0x02, 00163 ODR0 = 0x01, 00164 ODR12HZ = 0x00, 00165 ODR25HZ = 0x01, 00166 ODR50Hz = 0x02, 00167 ODR100HZ = 0x03, 00168 ODR200Hz = 0x04, 00169 ODR400HZ = 0x07 00170 } ADXL362_FILTER_CTL_reg_bits_t; 00171 00172 typedef enum { 00173 EXT_CLK = 0x40, 00174 LOW_NOISE1 = 0x20, 00175 LOW_NOISE0 = 0x10, 00176 NORMAL_OPERATION = 0x00, 00177 LOW_NOISE = 0x10, 00178 ULTRALOW_NOISE = 0x20, 00179 WAKEUP = 0x08, 00180 AUTOSLEEP = 0x04, 00181 MEASURE1 = 0x02, 00182 MEASURE0 = 0x01, 00183 } ADXL362_POWER_CTL_reg_bits_t; 00184 00185 /** SPI configuration & constructor */ 00186 // ADXL362(PinName CS = SPI_CS, PinName MOSI = SPI_MOSI, PinName MISO = 00187 // SPI_MISO, PinName SCK = SPI_SCK); 00188 ADXL362(PinName CS, PinName MOSI, PinName MISO, PinName SCK); 00189 void frequency(int hz); 00190 00191 /** Low level SPI bus comm methods */ 00192 void reset(void); 00193 void write_reg(ADXL362_register_t reg, uint8_t data); 00194 uint8_t read_reg(ADXL362_register_t reg); 00195 uint16_t read_reg_u16(ADXL362_register_t reg); 00196 void write_reg_u16(ADXL362_register_t reg, uint16_t data); 00197 00198 /** ADXL general register R/W methods */ 00199 void set_power_ctl_reg(uint8_t data); 00200 void set_filter_ctl_reg(uint8_t data); 00201 uint8_t read_status(); 00202 void set_mode(ADXL362_modes_t mode); 00203 00204 /** ADXL X/Y/Z/T scanning methods*/ 00205 uint64_t scan(); 00206 uint8_t scanx_u8(); 00207 uint16_t scanx(); 00208 uint8_t scany_u8(); 00209 uint16_t scany(); 00210 uint8_t scanz_u8(); 00211 uint16_t scanz(); 00212 uint16_t scant(); 00213 00214 /** ADXL362 activity methods */ 00215 void set_activity_threshold(uint16_t threshold); 00216 void set_activity_time(uint8_t time); 00217 void set_inactivity_threshold(uint16_t threshold); 00218 void set_inactivity_time(uint16_t time); 00219 void set_act_inact_ctl_reg(uint8_t data); 00220 00221 /** ADXL362 interrupt methods */ 00222 void set_interrupt1_pin(PinName in, uint8_t data, void (*callback_rising)(void), void (*callback_falling)(void), PinMode pull = PullNone); 00223 void set_interrupt2_pin(PinName in, uint8_t data, void (*callback_rising)(void), void (*callback_falling)(void), PinMode pull = PullNone); 00224 void enable_interrupt1(); 00225 void enable_interrupt2(); 00226 void disable_interrupt1(); 00227 void disable_interrupt2(); 00228 00229 void set_polling_interrupt1_pin(PinName in, uint8_t data, PinMode pull = PullNone); 00230 void set_polling_interrupt2_pin(PinName in, uint8_t data, PinMode pull = PullNone); 00231 00232 bool get_int1(); 00233 bool get_int2(); 00234 00235 /** ADXL362 FIFO methods */ 00236 uint16_t fifo_read_nr_of_entries(); 00237 void fifo_setup(bool store_temp, ADXL362_FIFO_modes_t mode, uint16_t nr_of_entries); 00238 uint16_t fifo_read_u16(); 00239 uint64_t fifo_scan(); 00240 00241 SPI adxl362; ///< SPI instance of the ADXL362 00242 DigitalOut cs; ///< DigitalOut instance for the chipselect of the ADXL362 00243 00244 private: 00245 00246 InterruptIn *_int1; 00247 InterruptIn *_int2; 00248 DigitalIn _int1_poll; 00249 DigitalIn _int2_poll; 00250 bool _int1_act_low; 00251 bool _int2_act_low; 00252 bool _temp_stored_in_fifo; 00253 00254 const static uint8_t _DUMMY_BYTE = 0xAA; 00255 const static uint8_t _WRITE_REG_CMD = 0x0A; // write register 00256 const static uint8_t _READ_REG_CMD = 0x0B; // read register 00257 const static uint8_t _READ_FIFO_CMD = 0x0D; // read FIFO 00258 const static uint8_t _SPI_MODE = 0; 00259 }; 00260 00261 #endif
Generated on Sun Jul 17 2022 01:37:39 by 1.7.2