temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IKobayashi 0:c88c3b616c00 1 /**
IKobayashi 0:c88c3b616c00 2 * @author Jose R Padron
IKobayashi 0:c88c3b616c00 3 *
IKobayashi 0:c88c3b616c00 4 * @section LICENSE
IKobayashi 0:c88c3b616c00 5 *
IKobayashi 0:c88c3b616c00 6 * Copyright (c) 2010 ARM Limited
IKobayashi 0:c88c3b616c00 7 *
IKobayashi 0:c88c3b616c00 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
IKobayashi 0:c88c3b616c00 9 * of this software and associated documentation files (the "Software"), to deal
IKobayashi 0:c88c3b616c00 10 * in the Software without restriction, including without limitation the rights
IKobayashi 0:c88c3b616c00 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
IKobayashi 0:c88c3b616c00 12 * copies of the Software, and to permit persons to whom the Software is
IKobayashi 0:c88c3b616c00 13 * furnished to do so, subject to the following conditions:
IKobayashi 0:c88c3b616c00 14 *
IKobayashi 0:c88c3b616c00 15 * The above copyright notice and this permission notice shall be included in
IKobayashi 0:c88c3b616c00 16 * all copies or substantial portions of the Software.
IKobayashi 0:c88c3b616c00 17 *
IKobayashi 0:c88c3b616c00 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IKobayashi 0:c88c3b616c00 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
IKobayashi 0:c88c3b616c00 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
IKobayashi 0:c88c3b616c00 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
IKobayashi 0:c88c3b616c00 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
IKobayashi 0:c88c3b616c00 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
IKobayashi 0:c88c3b616c00 24 * THE SOFTWARE.
IKobayashi 0:c88c3b616c00 25 *
IKobayashi 0:c88c3b616c00 26 * @section DESCRIPTION
IKobayashi 0:c88c3b616c00 27 *
IKobayashi 0:c88c3b616c00 28 * ADXL345, triple axis, digital interface, accelerometer.
IKobayashi 0:c88c3b616c00 29 *
IKobayashi 0:c88c3b616c00 30 * Datasheet:
IKobayashi 0:c88c3b616c00 31 *
IKobayashi 0:c88c3b616c00 32 * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf
IKobayashi 0:c88c3b616c00 33 *
IKobayashi 0:c88c3b616c00 34 * Things to know: SDO pin must be tied high for address 0x1D or low for address 0x53.
IKobayashi 0:c88c3b616c00 35 * It cannot be left floating.
IKobayashi 0:c88c3b616c00 36
IKobayashi 0:c88c3b616c00 37 */
IKobayashi 0:c88c3b616c00 38
IKobayashi 0:c88c3b616c00 39 #ifndef ADXL345_I2C_H
IKobayashi 0:c88c3b616c00 40 #define ADXL345_I2C_H
IKobayashi 0:c88c3b616c00 41
IKobayashi 0:c88c3b616c00 42 /**
IKobayashi 0:c88c3b616c00 43 * Includes
IKobayashi 0:c88c3b616c00 44 */
IKobayashi 0:c88c3b616c00 45 #include "mbed.h"
IKobayashi 0:c88c3b616c00 46
IKobayashi 0:c88c3b616c00 47 /**
IKobayashi 0:c88c3b616c00 48 * Defines
IKobayashi 0:c88c3b616c00 49 */
IKobayashi 0:c88c3b616c00 50 //Registers.
IKobayashi 0:c88c3b616c00 51 #define ADXL345_DEVID_REG 0x00
IKobayashi 0:c88c3b616c00 52 #define ADXL345_THRESH_TAP_REG 0x1D
IKobayashi 0:c88c3b616c00 53 #define ADXL345_OFSX_REG 0x1E
IKobayashi 0:c88c3b616c00 54 #define ADXL345_OFSY_REG 0x1F
IKobayashi 0:c88c3b616c00 55 #define ADXL345_OFSZ_REG 0x20
IKobayashi 0:c88c3b616c00 56 #define ADXL345_DUR_REG 0x21
IKobayashi 0:c88c3b616c00 57 #define ADXL345_LATENT_REG 0x22
IKobayashi 0:c88c3b616c00 58 #define ADXL345_WINDOW_REG 0x23
IKobayashi 0:c88c3b616c00 59 #define ADXL345_THRESH_ACT_REG 0x24
IKobayashi 0:c88c3b616c00 60 #define ADXL345_THRESH_INACT_REG 0x25
IKobayashi 0:c88c3b616c00 61 #define ADXL345_TIME_INACT_REG 0x26
IKobayashi 0:c88c3b616c00 62 #define ADXL345_ACT_INACT_CTL_REG 0x27
IKobayashi 0:c88c3b616c00 63 #define ADXL345_THRESH_FF_REG 0x28
IKobayashi 0:c88c3b616c00 64 #define ADXL345_TIME_FF_REG 0x29
IKobayashi 0:c88c3b616c00 65 #define ADXL345_TAP_AXES_REG 0x2A
IKobayashi 0:c88c3b616c00 66 #define ADXL345_ACT_TAP_STATUS_REG 0x2B
IKobayashi 0:c88c3b616c00 67 #define ADXL345_BW_RATE_REG 0x2C
IKobayashi 0:c88c3b616c00 68 #define ADXL345_POWER_CTL_REG 0x2D
IKobayashi 0:c88c3b616c00 69 #define ADXL345_INT_ENABLE_REG 0x2E
IKobayashi 0:c88c3b616c00 70 #define ADXL345_INT_MAP_REG 0x2F
IKobayashi 0:c88c3b616c00 71 #define ADXL345_INT_SOURCE_REG 0x30
IKobayashi 0:c88c3b616c00 72 #define ADXL345_DATA_FORMAT_REG 0x31
IKobayashi 0:c88c3b616c00 73 #define ADXL345_DATAX0_REG 0x32
IKobayashi 0:c88c3b616c00 74 #define ADXL345_DATAX1_REG 0x33
IKobayashi 0:c88c3b616c00 75 #define ADXL345_DATAY0_REG 0x34
IKobayashi 0:c88c3b616c00 76 #define ADXL345_DATAY1_REG 0x35
IKobayashi 0:c88c3b616c00 77 #define ADXL345_DATAZ0_REG 0x36
IKobayashi 0:c88c3b616c00 78 #define ADXL345_DATAZ1_REG 0x37
IKobayashi 0:c88c3b616c00 79 #define ADXL345_FIFO_CTL 0x38
IKobayashi 0:c88c3b616c00 80 #define ADXL345_FIFO_STATUS 0x39
IKobayashi 0:c88c3b616c00 81
IKobayashi 0:c88c3b616c00 82 //Data rate codes.
IKobayashi 0:c88c3b616c00 83 #define ADXL345_3200HZ 0x0F
IKobayashi 0:c88c3b616c00 84 #define ADXL345_1600HZ 0x0E
IKobayashi 0:c88c3b616c00 85 #define ADXL345_800HZ 0x0D
IKobayashi 0:c88c3b616c00 86 #define ADXL345_400HZ 0x0C
IKobayashi 0:c88c3b616c00 87 #define ADXL345_200HZ 0x0B
IKobayashi 0:c88c3b616c00 88 #define ADXL345_100HZ 0x0A
IKobayashi 0:c88c3b616c00 89 #define ADXL345_50HZ 0x09
IKobayashi 0:c88c3b616c00 90 #define ADXL345_25HZ 0x08
IKobayashi 0:c88c3b616c00 91 #define ADXL345_12HZ5 0x07
IKobayashi 0:c88c3b616c00 92 #define ADXL345_6HZ25 0x06
IKobayashi 0:c88c3b616c00 93
IKobayashi 0:c88c3b616c00 94 #define ADXL345_ID 0x1D
IKobayashi 0:c88c3b616c00 95 #define ADXL345_I2C_READ 0x3B
IKobayashi 0:c88c3b616c00 96 #define ADXL345_I2C_WRITE 0x3A
IKobayashi 0:c88c3b616c00 97 #define ADXL345_MULTI_BYTE 0x60
IKobayashi 0:c88c3b616c00 98
IKobayashi 0:c88c3b616c00 99 #define ADXL345_X 0x00
IKobayashi 0:c88c3b616c00 100 #define ADXL345_Y 0x01
IKobayashi 0:c88c3b616c00 101 #define ADXL345_Z 0x02
IKobayashi 0:c88c3b616c00 102
IKobayashi 0:c88c3b616c00 103 /**
IKobayashi 0:c88c3b616c00 104 * ADXL345 triple axis, digital interface, accelerometer.
IKobayashi 0:c88c3b616c00 105 */
IKobayashi 0:c88c3b616c00 106 class ADXL345_I2C {
IKobayashi 0:c88c3b616c00 107
IKobayashi 0:c88c3b616c00 108 public:
IKobayashi 0:c88c3b616c00 109
IKobayashi 0:c88c3b616c00 110 /**
IKobayashi 0:c88c3b616c00 111 * Constructor.
IKobayashi 0:c88c3b616c00 112 *
IKobayashi 0:c88c3b616c00 113 * @param sda mbed pin to use for sda line of I2C interface.
IKobayashi 0:c88c3b616c00 114 * @param scl mbed pin to use for SCL line of I2C interface.
IKobayashi 0:c88c3b616c00 115 * @param cs mbed pin to use for not chip select line of I2C interface.
IKobayashi 0:c88c3b616c00 116 */
IKobayashi 0:c88c3b616c00 117 ADXL345_I2C(PinName sda, PinName scl);
IKobayashi 0:c88c3b616c00 118
IKobayashi 0:c88c3b616c00 119 /**
IKobayashi 0:c88c3b616c00 120 * Read the device ID register on the device.
IKobayashi 0:c88c3b616c00 121 *
IKobayashi 0:c88c3b616c00 122 * @return The device ID code
IKobayashi 0:c88c3b616c00 123 */
IKobayashi 0:c88c3b616c00 124 char getDevId(void);
IKobayashi 0:c88c3b616c00 125
IKobayashi 0:c88c3b616c00 126 /**
IKobayashi 0:c88c3b616c00 127 * Read the tap threshold on the device.
IKobayashi 0:c88c3b616c00 128 *
IKobayashi 0:c88c3b616c00 129 * @return The tap threshold as an 8-bit number with a scale factor of
IKobayashi 0:c88c3b616c00 130 * 62.5mg/LSB.
IKobayashi 0:c88c3b616c00 131 */
IKobayashi 0:c88c3b616c00 132 int getTapThreshold(void);
IKobayashi 0:c88c3b616c00 133
IKobayashi 0:c88c3b616c00 134 /**
IKobayashi 0:c88c3b616c00 135 * Set the tap threshold.
IKobayashi 0:c88c3b616c00 136 *
IKobayashi 0:c88c3b616c00 137 * @param The tap threshold as an 8-bit number with a scale factor of
IKobayashi 0:c88c3b616c00 138 * 62.5mg/LSB.
IKobayashi 0:c88c3b616c00 139 */
IKobayashi 0:c88c3b616c00 140 void setTapThreshold(int threshold);
IKobayashi 0:c88c3b616c00 141
IKobayashi 0:c88c3b616c00 142 /**
IKobayashi 0:c88c3b616c00 143 * Get the current offset for a particular axis.
IKobayashi 0:c88c3b616c00 144 *
IKobayashi 0:c88c3b616c00 145 * @param axis 0x00 -> X-axis
IKobayashi 0:c88c3b616c00 146 * 0x01 -> Y-axis
IKobayashi 0:c88c3b616c00 147 * 0x02 -> Z-axis
IKobayashi 0:c88c3b616c00 148 * @return The current offset as an 8-bit 2's complement number with scale
IKobayashi 0:c88c3b616c00 149 * factor 15.6mg/LSB.
IKobayashi 0:c88c3b616c00 150 */
IKobayashi 0:c88c3b616c00 151 int getOffset(int axis);
IKobayashi 0:c88c3b616c00 152
IKobayashi 0:c88c3b616c00 153 /**
IKobayashi 0:c88c3b616c00 154 * Set the offset for a particular axis.
IKobayashi 0:c88c3b616c00 155 *
IKobayashi 0:c88c3b616c00 156 * @param axis 0x00 -> X-axis
IKobayashi 0:c88c3b616c00 157 * 0x01 -> Y-axis
IKobayashi 0:c88c3b616c00 158 * 0x02 -> Z-axis
IKobayashi 0:c88c3b616c00 159 * @param offset The offset as an 8-bit 2's complement number with scale
IKobayashi 0:c88c3b616c00 160 * factor 15.6mg/LSB.
IKobayashi 0:c88c3b616c00 161 */
IKobayashi 0:c88c3b616c00 162 void setOffset(int axis, char offset);
IKobayashi 0:c88c3b616c00 163
IKobayashi 0:c88c3b616c00 164 /**
IKobayashi 0:c88c3b616c00 165 * Get the tap duration required to trigger an event.
IKobayashi 0:c88c3b616c00 166 *
IKobayashi 0:c88c3b616c00 167 * @return The max time that an event must be above the tap threshold to
IKobayashi 0:c88c3b616c00 168 * qualify as a tap event, in microseconds.
IKobayashi 0:c88c3b616c00 169 */
IKobayashi 0:c88c3b616c00 170 int getTapDuration(void);
IKobayashi 0:c88c3b616c00 171
IKobayashi 0:c88c3b616c00 172 /**
IKobayashi 0:c88c3b616c00 173 * Set the tap duration required to trigger an event.
IKobayashi 0:c88c3b616c00 174 *
IKobayashi 0:c88c3b616c00 175 * @param duration_us The max time that an event must be above the tap
IKobayashi 0:c88c3b616c00 176 * threshold to qualify as a tap event, in microseconds.
IKobayashi 0:c88c3b616c00 177 * Time will be normalized by the scale factor which is
IKobayashi 0:c88c3b616c00 178 * 625us/LSB. A value of 0 disables the single/double
IKobayashi 0:c88c3b616c00 179 * tap functions.
IKobayashi 0:c88c3b616c00 180 */
IKobayashi 0:c88c3b616c00 181 void setTapDuration(int duration_us);
IKobayashi 0:c88c3b616c00 182
IKobayashi 0:c88c3b616c00 183 /**
IKobayashi 0:c88c3b616c00 184 * Get the tap latency between the detection of a tap and the time window.
IKobayashi 0:c88c3b616c00 185 *
IKobayashi 0:c88c3b616c00 186 * @return The wait time from the detection of a tap event to the start of
IKobayashi 0:c88c3b616c00 187 * the time window during which a possible second tap event can be
IKobayashi 0:c88c3b616c00 188 * detected in milliseconds.
IKobayashi 0:c88c3b616c00 189 */
IKobayashi 0:c88c3b616c00 190 float getTapLatency(void);
IKobayashi 0:c88c3b616c00 191
IKobayashi 0:c88c3b616c00 192 /**
IKobayashi 0:c88c3b616c00 193 * Set the tap latency between the detection of a tap and the time window.
IKobayashi 0:c88c3b616c00 194 *
IKobayashi 0:c88c3b616c00 195 * @param latency_ms The wait time from the detection of a tap event to the
IKobayashi 0:c88c3b616c00 196 * start of the time window during which a possible
IKobayashi 0:c88c3b616c00 197 * second tap event can be detected in milliseconds.
IKobayashi 0:c88c3b616c00 198 * A value of 0 disables the double tap function.
IKobayashi 0:c88c3b616c00 199 */
IKobayashi 0:c88c3b616c00 200 void setTapLatency(int latency_ms);
IKobayashi 0:c88c3b616c00 201
IKobayashi 0:c88c3b616c00 202 /**
IKobayashi 0:c88c3b616c00 203 * Get the time of window between tap latency and a double tap.
IKobayashi 0:c88c3b616c00 204 *
IKobayashi 0:c88c3b616c00 205 * @return The amount of time after the expiration of the latency time
IKobayashi 0:c88c3b616c00 206 * during which a second valid tap can begin, in milliseconds.
IKobayashi 0:c88c3b616c00 207 */
IKobayashi 0:c88c3b616c00 208 float getWindowTime(void);
IKobayashi 0:c88c3b616c00 209
IKobayashi 0:c88c3b616c00 210 /**
IKobayashi 0:c88c3b616c00 211 * Set the time of the window between tap latency and a double tap.
IKobayashi 0:c88c3b616c00 212 *
IKobayashi 0:c88c3b616c00 213 * @param window_ms The amount of time after the expiration of the latency
IKobayashi 0:c88c3b616c00 214 * time during which a second valid tap can begin,
IKobayashi 0:c88c3b616c00 215 * in milliseconds.
IKobayashi 0:c88c3b616c00 216 */
IKobayashi 0:c88c3b616c00 217 void setWindowTime(int window_ms);
IKobayashi 0:c88c3b616c00 218
IKobayashi 0:c88c3b616c00 219 /**
IKobayashi 0:c88c3b616c00 220 * Get the threshold value for detecting activity.
IKobayashi 0:c88c3b616c00 221 *
IKobayashi 0:c88c3b616c00 222 * @return The threshold value for detecting activity as an 8-bit number.
IKobayashi 0:c88c3b616c00 223 * Scale factor is 62.5mg/LSB.
IKobayashi 0:c88c3b616c00 224 */
IKobayashi 0:c88c3b616c00 225 int getActivityThreshold(void);
IKobayashi 0:c88c3b616c00 226
IKobayashi 0:c88c3b616c00 227 /**
IKobayashi 0:c88c3b616c00 228 * Set the threshold value for detecting activity.
IKobayashi 0:c88c3b616c00 229 *
IKobayashi 0:c88c3b616c00 230 * @param threshold The threshold value for detecting activity as an 8-bit
IKobayashi 0:c88c3b616c00 231 * number. Scale factor is 62.5mg/LSB. A value of 0 may
IKobayashi 0:c88c3b616c00 232 * result in undesirable behavior if the activity
IKobayashi 0:c88c3b616c00 233 * interrupt is enabled.
IKobayashi 0:c88c3b616c00 234 */
IKobayashi 0:c88c3b616c00 235 void setActivityThreshold(int threshold);
IKobayashi 0:c88c3b616c00 236
IKobayashi 0:c88c3b616c00 237 /**
IKobayashi 0:c88c3b616c00 238 * Get the threshold value for detecting inactivity.
IKobayashi 0:c88c3b616c00 239 *
IKobayashi 0:c88c3b616c00 240 * @return The threshold value for detecting inactivity as an 8-bit number.
IKobayashi 0:c88c3b616c00 241 * Scale factor is 62.5mg/LSB.
IKobayashi 0:c88c3b616c00 242 */
IKobayashi 0:c88c3b616c00 243 int getInactivityThreshold(void);
IKobayashi 0:c88c3b616c00 244
IKobayashi 0:c88c3b616c00 245 /**
IKobayashi 0:c88c3b616c00 246 * Set the threshold value for detecting inactivity.
IKobayashi 0:c88c3b616c00 247 *
IKobayashi 0:c88c3b616c00 248 * @param threshold The threshold value for detecting inactivity as an
IKobayashi 0:c88c3b616c00 249 * 8-bit number. Scale factor is 62.5mg/LSB.
IKobayashi 0:c88c3b616c00 250 */
IKobayashi 0:c88c3b616c00 251 void setInactivityThreshold(int threshold);
IKobayashi 0:c88c3b616c00 252
IKobayashi 0:c88c3b616c00 253 /**
IKobayashi 0:c88c3b616c00 254 * Get the time required for inactivity to be declared.
IKobayashi 0:c88c3b616c00 255 *
IKobayashi 0:c88c3b616c00 256 * @return The amount of time that acceleration must be less than the
IKobayashi 0:c88c3b616c00 257 * inactivity threshold for inactivity to be declared, in
IKobayashi 0:c88c3b616c00 258 * seconds.
IKobayashi 0:c88c3b616c00 259 */
IKobayashi 0:c88c3b616c00 260 int getTimeInactivity(void);
IKobayashi 0:c88c3b616c00 261
IKobayashi 0:c88c3b616c00 262 /**
IKobayashi 0:c88c3b616c00 263 * Set the time required for inactivity to be declared.
IKobayashi 0:c88c3b616c00 264 *
IKobayashi 0:c88c3b616c00 265 * @param inactivity The amount of time that acceleration must be less than
IKobayashi 0:c88c3b616c00 266 * the inactivity threshold for inactivity to be
IKobayashi 0:c88c3b616c00 267 * declared, in seconds. A value of 0 results in an
IKobayashi 0:c88c3b616c00 268 * interrupt when the output data is less than the
IKobayashi 0:c88c3b616c00 269 * threshold inactivity.
IKobayashi 0:c88c3b616c00 270 */
IKobayashi 0:c88c3b616c00 271 void setTimeInactivity(int timeInactivity);
IKobayashi 0:c88c3b616c00 272
IKobayashi 0:c88c3b616c00 273 /**
IKobayashi 0:c88c3b616c00 274 * Get the activity/inactivity control settings.
IKobayashi 0:c88c3b616c00 275 *
IKobayashi 0:c88c3b616c00 276 * D7 D6 D5 D4
IKobayashi 0:c88c3b616c00 277 * +-----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 278 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
IKobayashi 0:c88c3b616c00 279 * +-----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 280 *
IKobayashi 0:c88c3b616c00 281 * D3 D2 D1 D0
IKobayashi 0:c88c3b616c00 282 * +-------------+----------------+----------------+----------------+
IKobayashi 0:c88c3b616c00 283 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
IKobayashi 0:c88c3b616c00 284 * +-------------+----------------+----------------+----------------+
IKobayashi 0:c88c3b616c00 285 *
IKobayashi 0:c88c3b616c00 286 * See datasheet for details.
IKobayashi 0:c88c3b616c00 287 *
IKobayashi 0:c88c3b616c00 288 * @return The contents of the ACT_INACT_CTL register.
IKobayashi 0:c88c3b616c00 289 */
IKobayashi 0:c88c3b616c00 290 int getActivityInactivityControl(void);
IKobayashi 0:c88c3b616c00 291
IKobayashi 0:c88c3b616c00 292 /**
IKobayashi 0:c88c3b616c00 293 * Set the activity/inactivity control settings.
IKobayashi 0:c88c3b616c00 294 *
IKobayashi 0:c88c3b616c00 295 * D7 D6 D5 D4
IKobayashi 0:c88c3b616c00 296 * +-----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 297 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
IKobayashi 0:c88c3b616c00 298 * +-----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 299 *
IKobayashi 0:c88c3b616c00 300 * D3 D2 D1 D0
IKobayashi 0:c88c3b616c00 301 * +-------------+----------------+----------------+----------------+
IKobayashi 0:c88c3b616c00 302 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
IKobayashi 0:c88c3b616c00 303 * +-------------+----------------+----------------+----------------+
IKobayashi 0:c88c3b616c00 304 *
IKobayashi 0:c88c3b616c00 305 * See datasheet for details.
IKobayashi 0:c88c3b616c00 306 *
IKobayashi 0:c88c3b616c00 307 * @param settings The control byte to write to the ACT_INACT_CTL register.
IKobayashi 0:c88c3b616c00 308 */
IKobayashi 0:c88c3b616c00 309 void setActivityInactivityControl(int settings);
IKobayashi 0:c88c3b616c00 310
IKobayashi 0:c88c3b616c00 311 /**
IKobayashi 0:c88c3b616c00 312 * Get the threshold for free fall detection.
IKobayashi 0:c88c3b616c00 313 *
IKobayashi 0:c88c3b616c00 314 * @return The threshold value for free-fall detection, as an 8-bit number,
IKobayashi 0:c88c3b616c00 315 * with scale factor 62.5mg/LSB.
IKobayashi 0:c88c3b616c00 316 */
IKobayashi 0:c88c3b616c00 317 int getFreefallThreshold(void);
IKobayashi 0:c88c3b616c00 318
IKobayashi 0:c88c3b616c00 319 /**
IKobayashi 0:c88c3b616c00 320 * Set the threshold for free fall detection.
IKobayashi 0:c88c3b616c00 321 *
IKobayashi 0:c88c3b616c00 322 * @return The threshold value for free-fall detection, as an 8-bit number,
IKobayashi 0:c88c3b616c00 323 * with scale factor 62.5mg/LSB. A value of 0 may result in
IKobayashi 0:c88c3b616c00 324 * undesirable behavior if the free-fall interrupt is enabled.
IKobayashi 0:c88c3b616c00 325 * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended.
IKobayashi 0:c88c3b616c00 326 */
IKobayashi 0:c88c3b616c00 327 void setFreefallThreshold(int threshold);
IKobayashi 0:c88c3b616c00 328
IKobayashi 0:c88c3b616c00 329 /**
IKobayashi 0:c88c3b616c00 330 * Get the time required to generate a free fall interrupt.
IKobayashi 0:c88c3b616c00 331 *
IKobayashi 0:c88c3b616c00 332 * @return The minimum time that the value of all axes must be less than
IKobayashi 0:c88c3b616c00 333 * the freefall threshold to generate a free-fall interrupt, in
IKobayashi 0:c88c3b616c00 334 * milliseconds.
IKobayashi 0:c88c3b616c00 335 */
IKobayashi 0:c88c3b616c00 336 int getFreefallTime(void);
IKobayashi 0:c88c3b616c00 337
IKobayashi 0:c88c3b616c00 338 /**
IKobayashi 0:c88c3b616c00 339 * Set the time required to generate a free fall interrupt.
IKobayashi 0:c88c3b616c00 340 *
IKobayashi 0:c88c3b616c00 341 * @return The minimum time that the value of all axes must be less than
IKobayashi 0:c88c3b616c00 342 * the freefall threshold to generate a free-fall interrupt, in
IKobayashi 0:c88c3b616c00 343 * milliseconds. A value of 0 may result in undesirable behavior
IKobayashi 0:c88c3b616c00 344 * if the free-fall interrupt is enabled. Values between 100 ms
IKobayashi 0:c88c3b616c00 345 * and 350 ms (0x14 to 0x46) are recommended.
IKobayashi 0:c88c3b616c00 346 */
IKobayashi 0:c88c3b616c00 347 void setFreefallTime(int freefallTime_ms);
IKobayashi 0:c88c3b616c00 348
IKobayashi 0:c88c3b616c00 349 /**
IKobayashi 0:c88c3b616c00 350 * Get the axis tap settings.
IKobayashi 0:c88c3b616c00 351 *
IKobayashi 0:c88c3b616c00 352 * D3 D2 D1 D0
IKobayashi 0:c88c3b616c00 353 * +----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 354 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
IKobayashi 0:c88c3b616c00 355 * +----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 356 *
IKobayashi 0:c88c3b616c00 357 * (D7-D4 are 0s).
IKobayashi 0:c88c3b616c00 358 *
IKobayashi 0:c88c3b616c00 359 * See datasheet for more details.
IKobayashi 0:c88c3b616c00 360 *
IKobayashi 0:c88c3b616c00 361 * @return The contents of the TAP_AXES register.
IKobayashi 0:c88c3b616c00 362 */
IKobayashi 0:c88c3b616c00 363 int getTapAxisControl(void);
IKobayashi 0:c88c3b616c00 364
IKobayashi 0:c88c3b616c00 365 /**
IKobayashi 0:c88c3b616c00 366 * Set the axis tap settings.
IKobayashi 0:c88c3b616c00 367 *
IKobayashi 0:c88c3b616c00 368 * D3 D2 D1 D0
IKobayashi 0:c88c3b616c00 369 * +----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 370 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
IKobayashi 0:c88c3b616c00 371 * +----------+--------------+--------------+--------------+
IKobayashi 0:c88c3b616c00 372 *
IKobayashi 0:c88c3b616c00 373 * (D7-D4 are 0s).
IKobayashi 0:c88c3b616c00 374 *
IKobayashi 0:c88c3b616c00 375 * See datasheet for more details.
IKobayashi 0:c88c3b616c00 376 *
IKobayashi 0:c88c3b616c00 377 * @param The control byte to write to the TAP_AXES register.
IKobayashi 0:c88c3b616c00 378 */
IKobayashi 0:c88c3b616c00 379 void setTapAxisControl(int settings);
IKobayashi 0:c88c3b616c00 380
IKobayashi 0:c88c3b616c00 381 /**
IKobayashi 0:c88c3b616c00 382 * Get the source of a tap.
IKobayashi 0:c88c3b616c00 383 *
IKobayashi 0:c88c3b616c00 384 * @return The contents of the ACT_TAP_STATUS register.
IKobayashi 0:c88c3b616c00 385 */
IKobayashi 0:c88c3b616c00 386 int getTapSource(void);
IKobayashi 0:c88c3b616c00 387
IKobayashi 0:c88c3b616c00 388 /**
IKobayashi 0:c88c3b616c00 389 * Set the power mode.
IKobayashi 0:c88c3b616c00 390 *
IKobayashi 0:c88c3b616c00 391 * @param mode 0 -> Normal operation.
IKobayashi 0:c88c3b616c00 392 * 1 -> Reduced power operation.
IKobayashi 0:c88c3b616c00 393 */
IKobayashi 0:c88c3b616c00 394 void setPowerMode(char mode);
IKobayashi 0:c88c3b616c00 395
IKobayashi 0:c88c3b616c00 396 /**
IKobayashi 0:c88c3b616c00 397 * Set the data rate.
IKobayashi 0:c88c3b616c00 398 *
IKobayashi 0:c88c3b616c00 399 * @param rate The rate code (see #defines or datasheet).
IKobayashi 0:c88c3b616c00 400 */
IKobayashi 0:c88c3b616c00 401 void setDataRate(int rate);
IKobayashi 0:c88c3b616c00 402
IKobayashi 0:c88c3b616c00 403 /**
IKobayashi 0:c88c3b616c00 404 * Get the power control settings.
IKobayashi 0:c88c3b616c00 405 *
IKobayashi 0:c88c3b616c00 406 * See datasheet for details.
IKobayashi 0:c88c3b616c00 407 *
IKobayashi 0:c88c3b616c00 408 * @return The contents of the POWER_CTL register.
IKobayashi 0:c88c3b616c00 409 */
IKobayashi 0:c88c3b616c00 410 int getPowerControl(void);
IKobayashi 0:c88c3b616c00 411
IKobayashi 0:c88c3b616c00 412 /**
IKobayashi 0:c88c3b616c00 413 * Set the power control settings.
IKobayashi 0:c88c3b616c00 414 *
IKobayashi 0:c88c3b616c00 415 * See datasheet for details.
IKobayashi 0:c88c3b616c00 416 *
IKobayashi 0:c88c3b616c00 417 * @param The control byte to write to the POWER_CTL register.
IKobayashi 0:c88c3b616c00 418 */
IKobayashi 0:c88c3b616c00 419 void setPowerControl(int settings);
IKobayashi 0:c88c3b616c00 420
IKobayashi 0:c88c3b616c00 421 /**
IKobayashi 0:c88c3b616c00 422 * Get the interrupt enable settings.
IKobayashi 0:c88c3b616c00 423 *
IKobayashi 0:c88c3b616c00 424 * @return The contents of the INT_ENABLE register.
IKobayashi 0:c88c3b616c00 425 */
IKobayashi 0:c88c3b616c00 426 int getInterruptEnableControl(void);
IKobayashi 0:c88c3b616c00 427
IKobayashi 0:c88c3b616c00 428 /**
IKobayashi 0:c88c3b616c00 429 * Set the interrupt enable settings.
IKobayashi 0:c88c3b616c00 430 *
IKobayashi 0:c88c3b616c00 431 * @param settings The control byte to write to the INT_ENABLE register.
IKobayashi 0:c88c3b616c00 432 */
IKobayashi 0:c88c3b616c00 433 void setInterruptEnableControl(int settings);
IKobayashi 0:c88c3b616c00 434
IKobayashi 0:c88c3b616c00 435 /**
IKobayashi 0:c88c3b616c00 436 * Get the interrupt mapping settings.
IKobayashi 0:c88c3b616c00 437 *
IKobayashi 0:c88c3b616c00 438 * @return The contents of the INT_MAP register.
IKobayashi 0:c88c3b616c00 439 */
IKobayashi 0:c88c3b616c00 440 int getInterruptMappingControl(void);
IKobayashi 0:c88c3b616c00 441
IKobayashi 0:c88c3b616c00 442 /**
IKobayashi 0:c88c3b616c00 443 * Set the interrupt mapping settings.
IKobayashi 0:c88c3b616c00 444 *
IKobayashi 0:c88c3b616c00 445 * @param settings The control byte to write to the INT_MAP register.
IKobayashi 0:c88c3b616c00 446 */
IKobayashi 0:c88c3b616c00 447 void setInterruptMappingControl(int settings);
IKobayashi 0:c88c3b616c00 448
IKobayashi 0:c88c3b616c00 449 /**
IKobayashi 0:c88c3b616c00 450 * Get the interrupt source.
IKobayashi 0:c88c3b616c00 451 *
IKobayashi 0:c88c3b616c00 452 * @return The contents of the INT_SOURCE register.
IKobayashi 0:c88c3b616c00 453 */
IKobayashi 0:c88c3b616c00 454 int getInterruptSource(void);
IKobayashi 0:c88c3b616c00 455
IKobayashi 0:c88c3b616c00 456 /**
IKobayashi 0:c88c3b616c00 457 * Get the data format settings.
IKobayashi 0:c88c3b616c00 458 *
IKobayashi 0:c88c3b616c00 459 * @return The contents of the DATA_FORMAT register.
IKobayashi 0:c88c3b616c00 460 */
IKobayashi 0:c88c3b616c00 461 int getDataFormatControl(void);
IKobayashi 0:c88c3b616c00 462
IKobayashi 0:c88c3b616c00 463 /**
IKobayashi 0:c88c3b616c00 464 * Set the data format settings.
IKobayashi 0:c88c3b616c00 465 *
IKobayashi 0:c88c3b616c00 466 * @param settings The control byte to write to the DATA_FORMAT register.
IKobayashi 0:c88c3b616c00 467 */
IKobayashi 0:c88c3b616c00 468 void setDataFormatControl(int settings);
IKobayashi 0:c88c3b616c00 469
IKobayashi 0:c88c3b616c00 470 /**
IKobayashi 0:c88c3b616c00 471 * Get the output of all three axes.
IKobayashi 0:c88c3b616c00 472 *
IKobayashi 0:c88c3b616c00 473 * @param Pointer to a buffer to hold the accelerometer value for the
IKobayashi 0:c88c3b616c00 474 * x-axis, y-axis and z-axis [in that order].
IKobayashi 0:c88c3b616c00 475 */
IKobayashi 0:c88c3b616c00 476 void getOutput(int* readings);
IKobayashi 0:c88c3b616c00 477
IKobayashi 0:c88c3b616c00 478
IKobayashi 0:c88c3b616c00 479 /**
IKobayashi 0:c88c3b616c00 480 * Get acceleration of X axis.
IKobayashi 0:c88c3b616c00 481 *
IKobayashi 0:c88c3b616c00 482 *@return Accelerometer value for the x-axis.
IKobayashi 0:c88c3b616c00 483 */
IKobayashi 0:c88c3b616c00 484 int getAx();
IKobayashi 0:c88c3b616c00 485
IKobayashi 0:c88c3b616c00 486
IKobayashi 0:c88c3b616c00 487 /**
IKobayashi 0:c88c3b616c00 488 * Get acceleration of Y axis.
IKobayashi 0:c88c3b616c00 489 *
IKobayashi 0:c88c3b616c00 490 *@return Accelerometer value for the y-axis
IKobayashi 0:c88c3b616c00 491 */
IKobayashi 0:c88c3b616c00 492 int getAy();
IKobayashi 0:c88c3b616c00 493
IKobayashi 0:c88c3b616c00 494
IKobayashi 0:c88c3b616c00 495 /**
IKobayashi 0:c88c3b616c00 496 * Get acceleration of Z axis.
IKobayashi 0:c88c3b616c00 497 *
IKobayashi 0:c88c3b616c00 498 *@return Accelerometer value for the z-axis
IKobayashi 0:c88c3b616c00 499 */
IKobayashi 0:c88c3b616c00 500 int getAz();
IKobayashi 0:c88c3b616c00 501
IKobayashi 0:c88c3b616c00 502
IKobayashi 0:c88c3b616c00 503
IKobayashi 0:c88c3b616c00 504
IKobayashi 0:c88c3b616c00 505
IKobayashi 0:c88c3b616c00 506 /**
IKobayashi 0:c88c3b616c00 507 * Get the FIFO control settings.
IKobayashi 0:c88c3b616c00 508 *
IKobayashi 0:c88c3b616c00 509 * @return The contents of the FIFO_CTL register.
IKobayashi 0:c88c3b616c00 510 */
IKobayashi 0:c88c3b616c00 511 int getFifoControl(void);
IKobayashi 0:c88c3b616c00 512
IKobayashi 0:c88c3b616c00 513 /**
IKobayashi 0:c88c3b616c00 514 * Set the FIFO control settings.
IKobayashi 0:c88c3b616c00 515 *
IKobayashi 0:c88c3b616c00 516 * @param The control byte to write to the FIFO_CTL register.
IKobayashi 0:c88c3b616c00 517 */
IKobayashi 0:c88c3b616c00 518 void setFifoControl(int settings);
IKobayashi 0:c88c3b616c00 519
IKobayashi 0:c88c3b616c00 520 /**
IKobayashi 0:c88c3b616c00 521 * Get FIFO status.
IKobayashi 0:c88c3b616c00 522 *
IKobayashi 0:c88c3b616c00 523 * @return The contents of the FIFO_STATUS register.
IKobayashi 0:c88c3b616c00 524 */
IKobayashi 0:c88c3b616c00 525 int getFifoStatus(void);
IKobayashi 0:c88c3b616c00 526
IKobayashi 0:c88c3b616c00 527 private:
IKobayashi 0:c88c3b616c00 528 I2C i2c_;
IKobayashi 0:c88c3b616c00 529
IKobayashi 0:c88c3b616c00 530 /**
IKobayashi 0:c88c3b616c00 531 * Read one byte from a register on the device.
IKobayashi 0:c88c3b616c00 532 *
IKobayashi 0:c88c3b616c00 533 * @param address Address of the register to read.
IKobayashi 0:c88c3b616c00 534 *
IKobayashi 0:c88c3b616c00 535 * @return The contents of the register address.
IKobayashi 0:c88c3b616c00 536 */
IKobayashi 0:c88c3b616c00 537 char oneByteRead(char address);
IKobayashi 0:c88c3b616c00 538
IKobayashi 0:c88c3b616c00 539 /**
IKobayashi 0:c88c3b616c00 540 * Write one byte to a register on the device.
IKobayashi 0:c88c3b616c00 541 *
IKobayashi 0:c88c3b616c00 542 * @param address Address of the register to write to.
IKobayashi 0:c88c3b616c00 543 * @param data The data to write into the register.
IKobayashi 0:c88c3b616c00 544 */
IKobayashi 0:c88c3b616c00 545 void oneByteWrite(char address, char data);
IKobayashi 0:c88c3b616c00 546
IKobayashi 0:c88c3b616c00 547 /**
IKobayashi 0:c88c3b616c00 548 * Read Two consecutive bytes on the device.
IKobayashi 0:c88c3b616c00 549 *
IKobayashi 0:c88c3b616c00 550 * @param startAddress The address of the first register to read from.
IKobayashi 0:c88c3b616c00 551 * @param buffer Pointer to a buffer to store data read from the device.
IKobayashi 0:c88c3b616c00 552 *
IKobayashi 0:c88c3b616c00 553 */
IKobayashi 0:c88c3b616c00 554 void TwoByteRead(char startAddress, char* buffer);
IKobayashi 0:c88c3b616c00 555
IKobayashi 0:c88c3b616c00 556 /**
IKobayashi 0:c88c3b616c00 557 * Write Two consecutive bytes on the device.
IKobayashi 0:c88c3b616c00 558 *
IKobayashi 0:c88c3b616c00 559 * @param startAddress The address of the first register to write to.
IKobayashi 0:c88c3b616c00 560 * @param buffer Pointer to a buffer which contains the data to write.
IKobayashi 0:c88c3b616c00 561 *
IKobayashi 0:c88c3b616c00 562 */
IKobayashi 0:c88c3b616c00 563 void TwoByteWrite(char startAddress, char* buffer);
IKobayashi 0:c88c3b616c00 564
IKobayashi 0:c88c3b616c00 565 };
IKobayashi 0:c88c3b616c00 566
IKobayashi 0:c88c3b616c00 567 #endif /* ADXL345_I2C_H */