1 /* 2 * Copyright (c) 2013, Freescale Semiconductor, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * o Redistributions of source code must retain the above copyright notice, this list 9 * of conditions and the following disclaimer. 10 * 11 * o Redistributions in binary form must reproduce the above copyright notice, this 12 * list of conditions and the following disclaimer in the documentation and/or 13 * other materials provided with the distribution. 14 * 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 /*! 32 * @file 33 * @brief Public interface for the MMA8562 accelerometer driver. 34 * @ingroup diag_accel 35 */ 36 37 #ifndef __MMA8562_H__ 38 #define __MMA8562_H__ 39 40 #include "stdint.h" 41 42 //! @addtogroup diag_accel 43 //! @{ 44 45 //////////////////////////////////////////////////////////////////////////////// 46 // Definitions 47 //////////////////////////////////////////////////////////////////////////////// 48 49 //! @brief Error codes for the MMA8562 driver. 50 enum _mma8562_errors 51 { 52 kMMA8562_Invalid_I2C_Address_Error = -128 53 }; 54 55 //! @brief Register definitions for the MMA8562. 56 enum _mma8562_constants 57 { 58 kMMA8562_STATUS = 0x00, 59 kMMA8562_OUT_X_MSB = 0x01, 60 kMMA8562_OUT_X_LSB = 0x02, 61 kMMA8562_OUT_Y_MSB = 0x03, 62 kMMA8562_OUT_Y_LSB = 0x04, 63 kMMA8562_OUT_Z_MSB = 0x05, 64 kMMA8562_OUT_Z_LSB = 0x06, 65 kMMA8562_F_SETUP = 0x09, 66 kMMA8562_TRIG_CFG = 0x0a, 67 kMMA8562_SYSMOD = 0x0b, 68 kMMA8562_INT_SOURCE = 0x0c, 69 kMMA8562_WHO_AM_I = 0x0d, 70 kMMA8562_WHO_AM_I_Device_ID = 0x4a, 71 kMMA8562_XYZ_DATA_CFG = 0x0e, 72 kMMA8562_CTRL_REG1 = 0x2a, 73 kMMA8562_CTRL_REG2 = 0x2b, 74 kMMA8562_CTRL_REG3 = 0x2c, 75 kMMA8562_CTRL_REG4 = 0x2d, 76 kMMA8562_CTRL_REG5 = 0x2e 77 }; 78 79 //! @brief 3D acceleration values. 80 typedef struct _acceleration { 81 int16_t x; 82 int16_t y; 83 int16_t z; 84 } acceleration_t; 85 86 //////////////////////////////////////////////////////////////////////////////// 87 // API 88 //////////////////////////////////////////////////////////////////////////////// 89 90 #if defined(__cplusplus) 91 extern "C" { 92 #endif 93 94 extern int mma8562_hw_init(void); 95 96 extern void get_mma8562(uint8_t data); 97 98 extern rt_err_t mma8562_read_reg(rt_uint8_t reg, rt_uint8_t len, rt_uint8_t *buf); 99 100 extern rt_err_t mma8562_write_reg(rt_uint8_t reg, rt_uint8_t data); 101 102 #if defined(__cplusplus) 103 } 104 #endif 105 106 //! @} 107 108 #endif //__MMA8562_H__ 109 //////////////////////////////////////////////////////////////////////////////// 110 // EOF 111 //////////////////////////////////////////////////////////////////////////////// 112