A collection of Analog Devices drivers for the mbed platform

For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all

Committer:
Adrian Suciu
Date:
Tue May 17 15:15:19 2016 +0300
Revision:
20:9790e53d6e26
Parent:
19:fb92949e59c9
Refactoring and Doxygen tags

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Adrian Suciu 19:fb92949e59c9 1 #ifndef ADXL362_H_
Adrian Suciu 19:fb92949e59c9 2 #define ADXL362_H_
Adrian Suciu 19:fb92949e59c9 3
Adrian Suciu 20:9790e53d6e26 4 /**
Adrian Suciu 20:9790e53d6e26 5 * @file ADXL362.cpp
Adrian Suciu 20:9790e53d6e26 6 * @brief Header file for ADXL362
Adrian Suciu 20:9790e53d6e26 7 * @author Analog Devices Inc.
Adrian Suciu 20:9790e53d6e26 8 *
Adrian Suciu 20:9790e53d6e26 9 * For support please go to:
Adrian Suciu 20:9790e53d6e26 10 * Github: https://github.com/analogdevicesinc/mbed-adi
Adrian Suciu 20:9790e53d6e26 11 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
Adrian Suciu 20:9790e53d6e26 12 * Product: http://www.analog.com/adxl362
Adrian Suciu 20:9790e53d6e26 13 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
Adrian Suciu 20:9790e53d6e26 14
Adrian Suciu 20:9790e53d6e26 15 ********************************************************************************
Adrian Suciu 20:9790e53d6e26 16 * Copyright 2016(c) Analog Devices, Inc.
Adrian Suciu 20:9790e53d6e26 17 *
Adrian Suciu 20:9790e53d6e26 18 * All rights reserved.
Adrian Suciu 20:9790e53d6e26 19 *
Adrian Suciu 20:9790e53d6e26 20 * Redistribution and use in source and binary forms, with or without
Adrian Suciu 20:9790e53d6e26 21 * modification, are permitted provided that the following conditions are met:
Adrian Suciu 20:9790e53d6e26 22 * - Redistributions of source code must retain the above copyright
Adrian Suciu 20:9790e53d6e26 23 * notice, this list of conditions and the following disclaimer.
Adrian Suciu 20:9790e53d6e26 24 * - Redistributions in binary form must reproduce the above copyright
Adrian Suciu 20:9790e53d6e26 25 * notice, this list of conditions and the following disclaimer in
Adrian Suciu 20:9790e53d6e26 26 * the documentation and/or other materials provided with the
Adrian Suciu 20:9790e53d6e26 27 * distribution.
Adrian Suciu 20:9790e53d6e26 28 * - Neither the name of Analog Devices, Inc. nor the names of its
Adrian Suciu 20:9790e53d6e26 29 * contributors may be used to endorse or promote products derived
Adrian Suciu 20:9790e53d6e26 30 * from this software without specific prior written permission.
Adrian Suciu 20:9790e53d6e26 31 * - The use of this software may or may not infringe the patent rights
Adrian Suciu 20:9790e53d6e26 32 * of one or more patent holders. This license does not release you
Adrian Suciu 20:9790e53d6e26 33 * from the requirement that you obtain separate licenses from these
Adrian Suciu 20:9790e53d6e26 34 * patent holders to use this software.
Adrian Suciu 20:9790e53d6e26 35 * - Use of the software either in source or binary form, must be run
Adrian Suciu 20:9790e53d6e26 36 * on or directly connected to an Analog Devices Inc. component.
Adrian Suciu 20:9790e53d6e26 37 *
Adrian Suciu 20:9790e53d6e26 38 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
Adrian Suciu 20:9790e53d6e26 39 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
Adrian Suciu 20:9790e53d6e26 40 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Adrian Suciu 20:9790e53d6e26 41 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
Adrian Suciu 20:9790e53d6e26 42 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Adrian Suciu 20:9790e53d6e26 43 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
Adrian Suciu 20:9790e53d6e26 44 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Adrian Suciu 20:9790e53d6e26 45 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Adrian Suciu 20:9790e53d6e26 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Adrian Suciu 20:9790e53d6e26 47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Adrian Suciu 20:9790e53d6e26 48 *
Adrian Suciu 20:9790e53d6e26 49 ********************************************************************************/
Adrian Suciu 20:9790e53d6e26 50
Adrian Suciu 19:fb92949e59c9 51 #include "mbed.h"
Adrian Suciu 19:fb92949e59c9 52
Adrian Suciu 19:fb92949e59c9 53 class ADXL362
Adrian Suciu 19:fb92949e59c9 54 {
Adrian Suciu 19:fb92949e59c9 55 public:
Adrian Suciu 19:fb92949e59c9 56
Adrian Suciu 19:fb92949e59c9 57 /* Temperature parameters */
Adrian Suciu 19:fb92949e59c9 58 typedef enum {
Adrian Suciu 19:fb92949e59c9 59 DEVID_AD = 0x00,
Adrian Suciu 19:fb92949e59c9 60 DEVID_MST = 0x01,
Adrian Suciu 19:fb92949e59c9 61 PARTID = 0x02,
Adrian Suciu 19:fb92949e59c9 62 REVID = 0x03,
Adrian Suciu 19:fb92949e59c9 63 XDATA = 0x08,
Adrian Suciu 19:fb92949e59c9 64 YDATA = 0x09,
Adrian Suciu 19:fb92949e59c9 65 ZDATA = 0x0A,
Adrian Suciu 19:fb92949e59c9 66 STATUS = 0x0B,
Adrian Suciu 19:fb92949e59c9 67 FIFO_ENTRIES_L = 0x0C,
Adrian Suciu 19:fb92949e59c9 68 FIFO_ENTRIES_H = 0x0D,
Adrian Suciu 19:fb92949e59c9 69 XDATA_L = 0x0E,
Adrian Suciu 19:fb92949e59c9 70 XDATA_H = 0x0F,
Adrian Suciu 19:fb92949e59c9 71 YDATA_L = 0x10,
Adrian Suciu 19:fb92949e59c9 72 YDATA_H = 0x11,
Adrian Suciu 19:fb92949e59c9 73 ZDATA_L = 0x12,
Adrian Suciu 19:fb92949e59c9 74 ZDATA_H = 0x13,
Adrian Suciu 19:fb92949e59c9 75 TEMP_L = 0x14,
Adrian Suciu 19:fb92949e59c9 76 TEMP_H = 0x15,
Adrian Suciu 19:fb92949e59c9 77 // Reserved = 0x16;
Adrian Suciu 19:fb92949e59c9 78 // Reserved = 0x17;
Adrian Suciu 19:fb92949e59c9 79 SOFT_RESET = 0x1F,
Adrian Suciu 19:fb92949e59c9 80 THRESH_ACT_L = 0x20,
Adrian Suciu 19:fb92949e59c9 81 THRESH_ACT_H = 0x21,
Adrian Suciu 19:fb92949e59c9 82 TIME_ACT = 0x22,
Adrian Suciu 19:fb92949e59c9 83 THRESH_INACT_L = 0x23,
Adrian Suciu 19:fb92949e59c9 84 THRESH_INACT_H = 0x24,
Adrian Suciu 19:fb92949e59c9 85 TIME_INACT_L = 0x25,
Adrian Suciu 19:fb92949e59c9 86 TIME_INACT_H = 0x26,
Adrian Suciu 19:fb92949e59c9 87 ACT_INACT_CTL = 0x27,
Adrian Suciu 19:fb92949e59c9 88 FIFO_CONTROL = 0x28,
Adrian Suciu 19:fb92949e59c9 89 FIFO_SAMPLES = 0x29,
Adrian Suciu 19:fb92949e59c9 90 INTMAP1 = 0x2A,
Adrian Suciu 19:fb92949e59c9 91 INTMAP2 = 0x2B,
Adrian Suciu 19:fb92949e59c9 92 FILTER_CTL = 0x2C,
Adrian Suciu 19:fb92949e59c9 93 POWER_CTL = 0x2D,
Adrian Suciu 19:fb92949e59c9 94 SELF_TEST = 0x2E,
Adrian Suciu 19:fb92949e59c9 95 } ADXL362_register_t;
Adrian Suciu 19:fb92949e59c9 96
Adrian Suciu 19:fb92949e59c9 97 typedef enum {
Adrian Suciu 19:fb92949e59c9 98 STANDBY = 0x00,
Adrian Suciu 19:fb92949e59c9 99 MEASUREMENT = 0x02
Adrian Suciu 19:fb92949e59c9 100 } ADXL362_modes_t;
Adrian Suciu 19:fb92949e59c9 101
Adrian Suciu 19:fb92949e59c9 102 typedef enum {
Adrian Suciu 19:fb92949e59c9 103 ERR_USER_REGS = 0x80,
Adrian Suciu 19:fb92949e59c9 104 AWAKE = 0x40,
Adrian Suciu 19:fb92949e59c9 105 INACT = 0x20,
Adrian Suciu 19:fb92949e59c9 106 ACT = 0x10,
Adrian Suciu 19:fb92949e59c9 107 FIFO_OVERRUN = 0x08,
Adrian Suciu 19:fb92949e59c9 108 FIFO_WATERMARK = 0x04,
Adrian Suciu 19:fb92949e59c9 109 FIFO_READY = 0x02,
Adrian Suciu 19:fb92949e59c9 110 DATA_READY = 0x01
Adrian Suciu 19:fb92949e59c9 111 } ADXL362_STATUS_reg_bits_t;
Adrian Suciu 19:fb92949e59c9 112
Adrian Suciu 19:fb92949e59c9 113 typedef enum {
Adrian Suciu 19:fb92949e59c9 114 LINKLOOP1 = 0x20,
Adrian Suciu 19:fb92949e59c9 115 LINKLOOP0 = 0x10,
Adrian Suciu 19:fb92949e59c9 116 DEFAULTMODE = 0x00,
Adrian Suciu 19:fb92949e59c9 117 LINKED_MODE = 0x10,
Adrian Suciu 19:fb92949e59c9 118 LOOP_MODE = 0x30,
Adrian Suciu 19:fb92949e59c9 119 INACT_REF = 0x08,
Adrian Suciu 19:fb92949e59c9 120 INACT_EN = 0x04,
Adrian Suciu 19:fb92949e59c9 121 ACT_REF = 0x02,
Adrian Suciu 19:fb92949e59c9 122 ACT_EN = 0x01
Adrian Suciu 19:fb92949e59c9 123 } ADXL362_ACT_INACT_CTL_reg_bits_t;
Adrian Suciu 19:fb92949e59c9 124
Adrian Suciu 19:fb92949e59c9 125 typedef enum {
Adrian Suciu 19:fb92949e59c9 126 AH = 0x08,
Adrian Suciu 19:fb92949e59c9 127 FIFO_TEMP = 0x04,
Adrian Suciu 19:fb92949e59c9 128 FIFO_MODE1 = 0x02,
Adrian Suciu 19:fb92949e59c9 129 FIFO_MODE = 0x01,
Adrian Suciu 19:fb92949e59c9 130 } ADXL362_FIFO_CONTROL_reg_bits_t;
Adrian Suciu 19:fb92949e59c9 131
Adrian Suciu 19:fb92949e59c9 132 typedef enum {
Adrian Suciu 19:fb92949e59c9 133 FIFO_DISABLED = 0x00,
Adrian Suciu 19:fb92949e59c9 134 FIFO_OLDEST = 0x01,
Adrian Suciu 19:fb92949e59c9 135 FIFO_STREAM = 0x02,
Adrian Suciu 19:fb92949e59c9 136 FIFO_TRIGGERED = 0x03,
Adrian Suciu 19:fb92949e59c9 137 } ADXL362_FIFO_modes_t;
Adrian Suciu 19:fb92949e59c9 138
Adrian Suciu 19:fb92949e59c9 139 typedef enum {
Adrian Suciu 19:fb92949e59c9 140 INT_LOW = 0x80,
Adrian Suciu 19:fb92949e59c9 141 INT_AWAKE = 0x40,
Adrian Suciu 19:fb92949e59c9 142 INT_INACT = 0x20,
Adrian Suciu 19:fb92949e59c9 143 INT_ACT = 0x10,
Adrian Suciu 19:fb92949e59c9 144 INT_FIFO_OVERRUN = 0x08,
Adrian Suciu 19:fb92949e59c9 145 INT_FIFO_WATERMARK = 0x04,
Adrian Suciu 19:fb92949e59c9 146 INT_FIFO_READY = 0x02,
Adrian Suciu 19:fb92949e59c9 147 INT_DATA_READY = 0x01
Adrian Suciu 19:fb92949e59c9 148 } ADXL362_INTMAP_reg_bits_t;
Adrian Suciu 19:fb92949e59c9 149
Adrian Suciu 19:fb92949e59c9 150 typedef enum {
Adrian Suciu 19:fb92949e59c9 151 RANGE1 = 0x80,
Adrian Suciu 19:fb92949e59c9 152 RANGE0 = 0x40,
Adrian Suciu 19:fb92949e59c9 153 RANGE2G = 0x00,
Adrian Suciu 19:fb92949e59c9 154 RANGE4G = 0x40,
Adrian Suciu 19:fb92949e59c9 155 RANGE8G = 0x80,
Adrian Suciu 19:fb92949e59c9 156 HALF_BW = 0x10,
Adrian Suciu 19:fb92949e59c9 157 EXT_SAMPLE = 0x08,
Adrian Suciu 19:fb92949e59c9 158 ODR2 = 0x04,
Adrian Suciu 19:fb92949e59c9 159 ODR1 = 0x02,
Adrian Suciu 19:fb92949e59c9 160 ODR0 = 0x01,
Adrian Suciu 19:fb92949e59c9 161 ODR12HZ = 0x00,
Adrian Suciu 19:fb92949e59c9 162 ODR25HZ = 0x01,
Adrian Suciu 19:fb92949e59c9 163 ODR50Hz = 0x02,
Adrian Suciu 19:fb92949e59c9 164 ODR100HZ = 0x03,
Adrian Suciu 19:fb92949e59c9 165 ODR200Hz = 0x04,
Adrian Suciu 19:fb92949e59c9 166 ODR400HZ = 0x07
Adrian Suciu 19:fb92949e59c9 167 } ADXL362_FILTER_CTL_reg_bits_t;
Adrian Suciu 19:fb92949e59c9 168
Adrian Suciu 19:fb92949e59c9 169 typedef enum {
Adrian Suciu 19:fb92949e59c9 170 EXT_CLK = 0x40,
Adrian Suciu 19:fb92949e59c9 171 LOW_NOISE1 = 0x20,
Adrian Suciu 19:fb92949e59c9 172 LOW_NOISE0 = 0x10,
Adrian Suciu 19:fb92949e59c9 173 NORMAL_OPERATION = 0x00,
Adrian Suciu 19:fb92949e59c9 174 LOW_NOISE = 0x10,
Adrian Suciu 19:fb92949e59c9 175 ULTRALOW_NOISE = 0x20,
Adrian Suciu 19:fb92949e59c9 176 WAKEUP = 0x08,
Adrian Suciu 19:fb92949e59c9 177 AUTOSLEEP = 0x04,
Adrian Suciu 19:fb92949e59c9 178 MEASURE1 = 0x02,
Adrian Suciu 19:fb92949e59c9 179 MEASURE0 = 0x01,
Adrian Suciu 19:fb92949e59c9 180 } ADXL362_POWER_CTL_reg_bits_t;
Adrian Suciu 19:fb92949e59c9 181
Adrian Suciu 19:fb92949e59c9 182 /** SPI configuration & constructor */
Adrian Suciu 19:fb92949e59c9 183 ADXL362(PinName CS = SPI_CS, PinName MOSI = SPI_MOSI, PinName MISO =
Adrian Suciu 19:fb92949e59c9 184 SPI_MISO, PinName SCK = SPI_SCK);
Adrian Suciu 19:fb92949e59c9 185 void frequency(int hz);
Adrian Suciu 19:fb92949e59c9 186
Adrian Suciu 19:fb92949e59c9 187 /** Low level SPI bus comm methods */
Adrian Suciu 19:fb92949e59c9 188 void reset(void);
Adrian Suciu 19:fb92949e59c9 189 void write_reg(ADXL362_register_t reg, uint8_t data);
Adrian Suciu 19:fb92949e59c9 190 uint8_t read_reg(ADXL362_register_t reg);
Adrian Suciu 20:9790e53d6e26 191 uint16_t read_reg_u16(ADXL362_register_t reg);
Adrian Suciu 20:9790e53d6e26 192 void write_reg_u16(ADXL362_register_t reg, uint16_t data);
Adrian Suciu 19:fb92949e59c9 193
Adrian Suciu 20:9790e53d6e26 194 /** ADXL general register R/W methods */
Adrian Suciu 19:fb92949e59c9 195 void set_power_ctl_reg(uint8_t data);
Adrian Suciu 19:fb92949e59c9 196 void set_filter_ctl_reg(uint8_t data);
Adrian Suciu 20:9790e53d6e26 197 uint8_t read_status();
Adrian Suciu 20:9790e53d6e26 198 void set_mode(ADXL362_modes_t mode);
Adrian Suciu 19:fb92949e59c9 199
Adrian Suciu 20:9790e53d6e26 200 /** ADXL X/Y/Z/T scanning methods*/
Adrian Suciu 20:9790e53d6e26 201 uint64_t scan();
Adrian Suciu 19:fb92949e59c9 202 uint8_t scanx_u8();
Adrian Suciu 19:fb92949e59c9 203 uint16_t scanx();
Adrian Suciu 19:fb92949e59c9 204 uint8_t scany_u8();
Adrian Suciu 19:fb92949e59c9 205 uint16_t scany();
Adrian Suciu 19:fb92949e59c9 206 uint8_t scanz_u8();
Adrian Suciu 19:fb92949e59c9 207 uint16_t scanz();
Adrian Suciu 19:fb92949e59c9 208 uint16_t scant();
Adrian Suciu 19:fb92949e59c9 209
Adrian Suciu 20:9790e53d6e26 210 /** ADXL362 activity methods */
Adrian Suciu 19:fb92949e59c9 211 void set_activity_threshold(uint16_t threshold);
Adrian Suciu 19:fb92949e59c9 212 void set_activity_time(uint8_t time);
Adrian Suciu 19:fb92949e59c9 213 void set_inactivity_threshold(uint16_t threshold);
Adrian Suciu 19:fb92949e59c9 214 void set_inactivity_time(uint16_t time);
Adrian Suciu 19:fb92949e59c9 215 void set_act_inact_ctl_reg(uint8_t data);
Adrian Suciu 19:fb92949e59c9 216
Adrian Suciu 20:9790e53d6e26 217 /** ADXL362 interrupt methods */
Adrian Suciu 19:fb92949e59c9 218 void set_interrupt1_pin(PinName in, uint8_t data, void (*callback_rising)(void), void (*callback_falling)(void), PinMode pull = PullNone);
Adrian Suciu 19:fb92949e59c9 219 void set_interrupt2_pin(PinName in, uint8_t data, void (*callback_rising)(void), void (*callback_falling)(void), PinMode pull = PullNone);
Adrian Suciu 19:fb92949e59c9 220 void enable_interrupt1();
Adrian Suciu 19:fb92949e59c9 221 void enable_interrupt2();
Adrian Suciu 19:fb92949e59c9 222 void disable_interrupt1();
Adrian Suciu 19:fb92949e59c9 223 void disable_interrupt2();
Adrian Suciu 19:fb92949e59c9 224
Adrian Suciu 19:fb92949e59c9 225 void set_polling_interrupt1_pin(PinName in, uint8_t data, PinMode pull = PullNone);
Adrian Suciu 19:fb92949e59c9 226 void set_polling_interrupt2_pin(PinName in, uint8_t data, PinMode pull = PullNone);
Adrian Suciu 19:fb92949e59c9 227
Adrian Suciu 19:fb92949e59c9 228 bool get_int1();
Adrian Suciu 19:fb92949e59c9 229 bool get_int2();
Adrian Suciu 19:fb92949e59c9 230
Adrian Suciu 20:9790e53d6e26 231 /** ADXL362 FIFO methods */
Adrian Suciu 19:fb92949e59c9 232 uint16_t fifo_read_nr_of_entries();
Adrian Suciu 19:fb92949e59c9 233 void fifo_setup(bool store_temp, ADXL362_FIFO_modes_t mode, uint16_t nr_of_entries);
Adrian Suciu 19:fb92949e59c9 234 uint16_t fifo_read_u16();
Adrian Suciu 19:fb92949e59c9 235 uint64_t fifo_scan();
Adrian Suciu 19:fb92949e59c9 236
Adrian Suciu 20:9790e53d6e26 237 SPI adxl362; ///< SPI instance of the ADXL362
Adrian Suciu 20:9790e53d6e26 238 DigitalOut cs; ///< DigitalOut instance for the chipselect of the ADXL362
Adrian Suciu 19:fb92949e59c9 239
Adrian Suciu 19:fb92949e59c9 240 private:
Adrian Suciu 19:fb92949e59c9 241
Adrian Suciu 20:9790e53d6e26 242 InterruptIn *_int1;
Adrian Suciu 20:9790e53d6e26 243 InterruptIn *_int2;
Adrian Suciu 20:9790e53d6e26 244 DigitalIn _int1_poll;
Adrian Suciu 20:9790e53d6e26 245 DigitalIn _int2_poll;
Adrian Suciu 20:9790e53d6e26 246 bool _int1_act_low;
Adrian Suciu 20:9790e53d6e26 247 bool _int2_act_low;
Adrian Suciu 20:9790e53d6e26 248 bool _temp_stored_in_fifo;
Adrian Suciu 19:fb92949e59c9 249
Adrian Suciu 20:9790e53d6e26 250 const static uint8_t _DUMMY_BYTE = 0xAA;
Adrian Suciu 20:9790e53d6e26 251 const static uint8_t _WRITE_REG_CMD = 0x0A; // write register
Adrian Suciu 20:9790e53d6e26 252 const static uint8_t _READ_REG_CMD = 0x0B; // read register
Adrian Suciu 20:9790e53d6e26 253 const static uint8_t _READ_FIFO_CMD = 0x0D; // read FIFO
Adrian Suciu 19:fb92949e59c9 254 const static uint8_t _SPI_MODE = 0;
Adrian Suciu 19:fb92949e59c9 255 };
Adrian Suciu 19:fb92949e59c9 256
Adrian Suciu 19:fb92949e59c9 257 #endif