bmm150.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /**
  2. * Copyright (C) 2015 - 2016 Bosch Sensortec GmbH
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of the copyright holder nor the names of the
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  20. * 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 COPYRIGHT HOLDER
  23. * OR CONTRIBUTORS BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  25. * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  33. *
  34. * The information provided is believed to be accurate and reliable.
  35. * The copyright holder assumes no responsibility
  36. * for the consequences of use
  37. * of such information nor for any infringement of patents or
  38. * other rights of third parties which may result from its use.
  39. * No license is granted by implication or otherwise under any patent or
  40. * patent rights of the copyright holder.
  41. *
  42. * @file bmm150.h
  43. * @date 12 Sep 2017
  44. * @version 1.0.0
  45. *
  46. */
  47. /*! @file bmm150.h */
  48. /*!
  49. * @defgroup BMM150 SENSOR API
  50. * @{*/
  51. #ifndef BMM150_H__
  52. #define BMM150_H__
  53. /*! CPP guard */
  54. #ifdef __cplusplus
  55. extern "C"
  56. {
  57. #endif
  58. /********************************************************************/
  59. /* header files */
  60. #include "bmm150_defs.h"
  61. /********************************************************************/
  62. /* (extern) variable declarations */
  63. /********************************************************************/
  64. /* function prototype declarations */
  65. /*!
  66. * @brief This API is the entry point, Call this API before using other APIs.
  67. * This API reads the chip-id of the sensor which is the first step to
  68. * verify the sensor and also it configures the read mechanism of SPI and
  69. * I2C interface.
  70. *
  71. * @param[in,out] dev : Structure instance of bmm150_dev
  72. * @note : Refer user guide for detailed info.
  73. *
  74. * @return Result of API execution status
  75. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  76. */
  77. int8_t bmm150_init(struct bmm150_dev *dev);
  78. /*!
  79. * @brief This API writes the given data to the register address
  80. * of the sensor.
  81. *
  82. * @param[in] reg_addr : Register address from where the data to be written.
  83. * @param[in] reg_data : Pointer to data buffer which is to be written
  84. * in the reg_addr of sensor.
  85. * @param[in] len : No of bytes of data to write..
  86. * @param[in] dev : Structure instance of bmm150_dev.
  87. *
  88. * @return Result of API execution status
  89. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  90. */
  91. int8_t bmm150_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bmm150_dev *dev);
  92. /*!
  93. * @brief This API reads the data from the given register address of sensor.
  94. *
  95. * @param[in] reg_addr : Register address from where the data to be read
  96. * @param[out] reg_data : Pointer to data buffer to store the read data.
  97. * @param[in] len : No of bytes of data to be read.
  98. * @param[in] dev : Structure instance of bmm150_dev.
  99. *
  100. * @return Result of API execution status
  101. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  102. */
  103. int8_t bmm150_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct bmm150_dev *dev);
  104. /*!
  105. * @brief This API is used to perform soft-reset of the sensor
  106. * where all the registers are reset to their default values except 0x4B.
  107. *
  108. * @param[in] dev : Structure instance of bmm150_dev.
  109. *
  110. * @return Result of API execution status
  111. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  112. */
  113. int8_t bmm150_soft_reset(const struct bmm150_dev *dev);
  114. /*!
  115. * @brief This API is used to set the power mode of the sensor.
  116. *
  117. * @param[in] dev : Structure instance of bmm150_dev.
  118. *
  119. * dev->settings.pwr_mode | Power mode
  120. * ------------------------|-----------------------
  121. * 0x00 | BMM150_NORMAL_MODE
  122. * 0x01 | BMM150_FORCED_MODE
  123. * 0x03 | BMM150_SLEEP_MODE
  124. * 0x04 | BMM150_SUSPEND_MODE
  125. *
  126. * @return Result of API execution status
  127. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  128. */
  129. int8_t bmm150_set_op_mode(struct bmm150_dev *dev);
  130. /*!
  131. * @brief This API is used to get the power mode of the sensor.
  132. *
  133. * @param[out] op_mode : power mode of the sensor.
  134. * @param[in] dev : Structure instance of bmm150_dev.
  135. *
  136. * op_mode | Power mode
  137. * -------------|-----------------------
  138. * 0x00 | BMM150_NORMAL_MODE
  139. * 0x01 | BMM150_FORCED_MODE
  140. * 0x03 | BMM150_SLEEP_MODE
  141. * 0x04 | BMM150_SUSPEND_MODE
  142. *
  143. * @return Result of API execution status
  144. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  145. */
  146. int8_t bmm150_get_op_mode(uint8_t *op_mode, const struct bmm150_dev *dev);
  147. /*!
  148. * @brief This API is used to set the preset mode of the sensor.
  149. *
  150. * @param[in] dev : Structure instance of bmm150_dev.
  151. *
  152. * dev->settings.preset_mode | Preset mode
  153. * ---------------------------|----------------------------------
  154. * 0x01 | BMM150_PRESETMODE_LOWPOWER
  155. * 0x02 | BMM150_PRESETMODE_REGULAR
  156. * 0x03 | BMM150_PRESETMODE_HIGHACCURACY
  157. * 0x04 | BMM150_PRESETMODE_ENHANCED
  158. *
  159. * @return Result of API execution status
  160. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  161. */
  162. int8_t bmm150_set_presetmode(struct bmm150_dev *dev);
  163. /*!
  164. * @brief This API sets the sensor settings based on the desired_settings
  165. * and the dev structure configuration
  166. *
  167. * @param[in] desired_settings : Selection macro for selecting the setting.
  168. * @param[in] dev : Structure instance of bmm150_dev.
  169. *
  170. * @note Assign the sensor setting macros (multiple macros can be
  171. * set by doing a bitwise-OR operation) to the desired_settings parameter
  172. * of this API to perform the corresponding setting.
  173. *
  174. * @note threshold interrupt for each axes are set by using bitwise AND
  175. * operation of the following macros
  176. * - BMM150_THRESHOLD_X
  177. * - BMM150_THRESHOLD_Y
  178. * - BMM150_THRESHOLD_Z
  179. *
  180. * desired_settings | Selected sensor setting macros
  181. * -------------------|--------------------------------
  182. * 0x0001 | BMM150_DATA_RATE_SEL
  183. * 0x0002 | BMM150_CONTROL_MEASURE_SEL
  184. * 0x0004 | BMM150_XY_REP_SEL
  185. * 0x0008 | BMM150_Z_REP_SEL
  186. * 0x0010 | BMM150_DRDY_PIN_EN_SEL
  187. * 0x0020 | BMM150_INT_PIN_EN_SEL
  188. * 0x0040 | BMM150_DRDY_POLARITY_SEL
  189. * 0x0080 | BMM150_INT_LATCH_SEL
  190. * 0x0100 | BMM150_INT_POLARITY_SEL
  191. * 0x0200 | BMM150_DATA_OVERRUN_INT_SEL
  192. * 0x0400 | BMM150_OVERFLOW_INT_SEL
  193. * 0x0800 | BMM150_HIGH_THRESHOLD_INT_SEL
  194. * 0x1000 | BMM150_LOW_THRESHOLD_INT_SEL
  195. * 0x2000 | BMM150_LOW_THRESHOLD_SETTING_SEL
  196. * 0x4000 | BMM150_HIGH_THRESHOLD_SETTING_SEL
  197. *
  198. * @return Result of API execution status
  199. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  200. */
  201. int8_t bmm150_set_sensor_settings(uint16_t desired_settings, const struct bmm150_dev *dev);
  202. /*!
  203. * @brief This API gets all the sensor settings and updates the dev structure
  204. *
  205. * @param[in] dev : Structure instance of bmm150_dev.
  206. *
  207. * @return Result of API execution status
  208. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  209. */
  210. int8_t bmm150_get_sensor_settings(struct bmm150_dev *dev);
  211. /*!
  212. * @brief This API reads the magnetometer data from registers 0x42 to 0x49
  213. * and updates the dev structure with compensated mag data in micro-tesla
  214. * if using floating point, and 16 * micro-teslas if using int16_t for the data
  215. *
  216. * @param[in,out] dev : Structure instance of bmm150_dev.
  217. *
  218. * @note The output mag data can be obtained either in int16_t or float format
  219. * using this API.
  220. * @note Enable the macro "BMM150_USE_FLOATING_POINT" in the bmm150_defs.h
  221. * file and call this API to get the mag data in float,
  222. * disable this macro to get the mag data in int16_t format
  223. *
  224. * Mag data output(micro-tesla) | Mag data in dev structure(int16_t/float)
  225. * --------------------------------|------------------------------------------
  226. * X-axis data | dev->data.x
  227. * Y-axis data | dev->data.y
  228. * Z-axis data | dev->data.z
  229. *
  230. * @return Result of API execution status
  231. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  232. */
  233. int8_t bmm150_read_mag_data(struct bmm150_dev *dev);
  234. /*!
  235. * @brief This API is used to perform the complete self test
  236. * (both normal and advanced) for the BMM150 sensor
  237. *
  238. * @param[in] self_test_mode : The type of self test to be performed
  239. * @param[in] dev : Structure instance of bmm150_dev.
  240. *
  241. * self_test_mode | Self test enabled
  242. * --------------------|--------------------------
  243. * 0 | BMM150_NORMAL_SELF_TEST
  244. * 1 | BMM150_ADVANCED_SELF_TEST
  245. *
  246. * @note The return value of this API gives us the result of self test.
  247. *
  248. * @note Performing advanced self test does soft reset of the sensor, User can
  249. * set the desired settings after performing the advanced self test.
  250. *
  251. * @return Result of API execution status and self test result.
  252. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  253. *
  254. * Return value | Result of self test
  255. * --------------------|---------------------------------
  256. * 0 | BMM150_OK
  257. * 1 | BMM150_W_NORMAL_SELF_TEST_YZ_FAIL
  258. * 2 | BMM150_W_NORMAL_SELF_TEST_XZ_FAIL
  259. * 3 | BMM150_W_NORMAL_SELF_TEST_Z_FAIL
  260. * 4 | BMM150_W_NORMAL_SELF_TEST_XY_FAIL
  261. * 5 | BMM150_W_NORMAL_SELF_TEST_Y_FAIL
  262. * 6 | BMM150_W_NORMAL_SELF_TEST_X_FAIL
  263. * 7 | BMM150_W_NORMAL_SELF_TEST_XYZ_FAIL
  264. * 8 | BMM150_W_ADV_SELF_TEST_FAIL
  265. *
  266. */
  267. int8_t bmm150_perform_self_test(uint8_t self_test_mode, struct bmm150_dev *dev);
  268. /*!
  269. * @brief This API obtains the status flags of all interrupt
  270. * which is used to check for the assertion of interrupts
  271. *
  272. * @param[in,out] dev : Structure instance of bmm150_dev.
  273. *
  274. * @note The status flags of all the interrupts are stored in the
  275. * dev->int_status.
  276. *
  277. * @note The value of dev->int_status is performed a bitwise AND operation
  278. * with predefined interrupt status macros to find the interrupt status
  279. * which is either set or reset.
  280. *
  281. * Ex.
  282. * if (dev->int_status & BMM150_DATA_READY_INT)
  283. * {
  284. * Occurrence of data ready interrupt
  285. * } else {
  286. * No interrupt occurred
  287. * }
  288. *
  289. * @return Result of API execution status and self test result.
  290. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  291. */
  292. int8_t bmm150_get_interrupt_status(struct bmm150_dev *dev);
  293. /*!
  294. * @brief This API is used to compensate the raw mag data
  295. *
  296. * @param[in] aux_data : Raw mag data obtained from BMI160 registers
  297. * @param[in,out] dev : Structure instance of bmm150_dev.
  298. *
  299. * @return Result of API execution status and self test result.
  300. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  301. */
  302. int8_t bmm150_aux_mag_data(uint8_t *aux_data, struct bmm150_dev *dev);
  303. #ifdef __cplusplus
  304. }
  305. #endif /* End of CPP guard */
  306. #endif /* BMM150_H__ */
  307. /** @}*/