First commit
[hackover2013-badge-firmware.git] / drivers / sensors / adxl345 / adxl345.h
diff --git a/drivers/sensors/adxl345/adxl345.h b/drivers/sensors/adxl345/adxl345.h
new file mode 100644 (file)
index 0000000..7089e8a
--- /dev/null
@@ -0,0 +1,101 @@
+/**************************************************************************/
+/*! 
+    @file     adxl345.h
+    @author   K. Townsend (microBuilder.eu)
+
+    @section LICENSE
+
+    Software License Agreement (BSD License)
+
+    Copyright (c) 2012, K. Townsend
+    All rights reserved.
+
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+    1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+    2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+    3. Neither the name of the copyright holders nor the
+    names of its contributors may be used to endorse or promote products
+    derived from this software without specific prior written permission.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
+    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/**************************************************************************/
+
+#ifndef _ADXL345_H_
+#define _ADXL345_H_
+
+#include "projectconfig.h"
+#include "core/i2c/i2c.h"
+
+/*=========================================================================
+    I2C ADDRESS/BITS
+    -----------------------------------------------------------------------*/
+    #define ADXL345_ADDRESS                 (0xA6)    // Assumes ALT address pin low ... use 0x3A with ALT high
+    #define ADXL345_READBIT                 (0x01)
+/*=========================================================================*/
+
+/*=========================================================================
+    REGISTERS
+    -----------------------------------------------------------------------*/
+    #define ADXL345_REG_DEVID               (0x00)    // Device ID
+    #define ADXL345_REG_THRESH_TAP          (0x1D)    // Tap threshold
+    #define ADXL345_REG_OFSX                (0x1E)    // X-axis offset
+    #define ADXL345_REG_OFSY                (0x1F)    // Y-axis offset
+    #define ADXL345_REG_OFSZ                (0x20)    // Z-axis offset
+    #define ADXL345_REG_DUR                 (0x21)    // Tap duration
+    #define ADXL345_REG_LATENT              (0x22)    // Tap latency
+    #define ADXL345_REG_WINDOW              (0x23)    // Tap window
+    #define ADXL345_REG_THRESH_ACT          (0x24)    // Activity threshold
+    #define ADXL345_REG_THRESH_INACT        (0x25)    // Inactivity threshold
+    #define ADXL345_REG_TIME_INACT          (0x26)    // Inactivity time
+    #define ADXL345_REG_ACT_INACT_CTL       (0x27)    // Axis enable control for activity and inactivity detection
+    #define ADXL345_REG_THRESH_FF           (0x28)    // Free-fall threshold
+    #define ADXL345_REG_TIME_FF             (0x29)    // Free-fall time
+    #define ADXL345_REG_TAP_AXES            (0x2A)    // Axis control for single/double tap
+    #define ADXL345_REG_ACT_TAP_STATUS      (0x2B)    // Source for single/double tap
+    #define ADXL345_REG_BW_RATE             (0x2C)    // Data rate and power mode control
+    #define ADXL345_REG_POWER_CTL           (0x2D)    // Power-saving features control
+    #define ADXL345_REG_INT_ENABLE          (0x2E)    // Interrupt enable control
+    #define ADXL345_REG_INT_MAP             (0x2F)    // Interrupt mapping control
+    #define ADXL345_REG_INT_SOURCE          (0x30)    // Source of interrupts
+    #define ADXL345_REG_DATA_FORMAT         (0x31)    // Data format control
+    #define ADXL345_REG_DATAX0              (0x32)    // X-axis data 0
+    #define ADXL345_REG_DATAX1              (0x33)    // X-axis data 1
+    #define ADXL345_REG_DATAY0              (0x34)    // Y-axis data 0
+    #define ADXL345_REG_DATAY1              (0x35)    // Y-axis data 1
+    #define ADXL345_REG_DATAZ0              (0x36)    // Z-axis data 0
+    #define ADXL345_REG_DATAZ1              (0x37)    // Z-axis data 1
+    #define ADXL345_REG_FIFO_CTL            (0x38)    // FIFO control
+    #define ADXL345_REG_FIFO_STATUS         (0x39)    // FIFO status
+/*=========================================================================*/
+
+typedef enum
+{
+  ADXL345_ERROR_OK = 0,                // Everything executed normally
+  ADXL345_ERROR_I2CINIT,               // Unable to initialise I2C
+  ADXL345_ERROR_I2CBUSY,               // I2C already in use
+  ADXL345_ERROR_NOCONNECTION,          // Unable to read device ID during init
+  ADXL345_ERROR_LAST
+}
+adxl345Error_t;
+
+adxl345Error_t adxl345Init(void);
+adxl345Error_t adxl345GetDeviceID(uint8_t *id);
+adxl345Error_t adxl345GetXYZ(int16_t *x, int16_t *y, int16_t *z);
+
+#endif
+
+
This page took 0.021041 seconds and 4 git commands to generate.