drv_mma8562.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @file
  32. * @brief Public interface for the MMA8562 accelerometer driver.
  33. * @ingroup diag_accel
  34. */
  35. #ifndef __MMA8562_H__
  36. #define __MMA8562_H__
  37. #include "stdint.h"
  38. //! @addtogroup diag_accel
  39. //! @{
  40. ////////////////////////////////////////////////////////////////////////////////
  41. // Definitions
  42. ////////////////////////////////////////////////////////////////////////////////
  43. //! @brief Error codes for the MMA8562 driver.
  44. enum _mma8562_errors
  45. {
  46. kMMA8562_Invalid_I2C_Address_Error = -128
  47. };
  48. //! @brief Register definitions for the MMA8562.
  49. enum _mma8562_constants
  50. {
  51. kMMA8562_STATUS = 0x00,
  52. kMMA8562_OUT_X_MSB = 0x01,
  53. kMMA8562_OUT_X_LSB = 0x02,
  54. kMMA8562_OUT_Y_MSB = 0x03,
  55. kMMA8562_OUT_Y_LSB = 0x04,
  56. kMMA8562_OUT_Z_MSB = 0x05,
  57. kMMA8562_OUT_Z_LSB = 0x06,
  58. kMMA8562_F_SETUP = 0x09,
  59. kMMA8562_TRIG_CFG = 0x0a,
  60. kMMA8562_SYSMOD = 0x0b,
  61. kMMA8562_INT_SOURCE = 0x0c,
  62. kMMA8562_WHO_AM_I = 0x0d,
  63. kMMA8562_WHO_AM_I_Device_ID = 0x4a,
  64. kMMA8562_XYZ_DATA_CFG = 0x0e,
  65. kMMA8562_CTRL_REG1 = 0x2a,
  66. kMMA8562_CTRL_REG2 = 0x2b,
  67. kMMA8562_CTRL_REG3 = 0x2c,
  68. kMMA8562_CTRL_REG4 = 0x2d,
  69. kMMA8562_CTRL_REG5 = 0x2e
  70. };
  71. //! @brief 3D acceleration values.
  72. typedef struct _acceleration {
  73. int16_t x;
  74. int16_t y;
  75. int16_t z;
  76. } acceleration_t;
  77. ////////////////////////////////////////////////////////////////////////////////
  78. // API
  79. ////////////////////////////////////////////////////////////////////////////////
  80. #if defined(__cplusplus)
  81. extern "C" {
  82. #endif
  83. extern int mma8562_hw_init(void);
  84. extern void get_mma8562(uint8_t data);
  85. extern rt_err_t mma8562_read_reg(rt_uint8_t reg, rt_uint8_t len, rt_uint8_t *buf);
  86. extern rt_err_t mma8562_write_reg(rt_uint8_t reg, rt_uint8_t data);
  87. #if defined(__cplusplus)
  88. }
  89. #endif
  90. //! @}
  91. #endif //__MMA8562_H__
  92. ////////////////////////////////////////////////////////////////////////////////
  93. // EOF
  94. ////////////////////////////////////////////////////////////////////////////////