df220.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**
  2. * Copyright (C) 2012 - 2019 MiraMEMS
  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 df220.h
  43. * @date 17 Apr 2019
  44. * @version 0.0.1
  45. * @brief
  46. *
  47. */
  48. /*! @file df220.h */
  49. /*!
  50. * @defgroup DF220 SENSOR API
  51. * @{
  52. */
  53. #ifndef DF220_H__
  54. #define DF220_H__
  55. /*! CPP guard */
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. /*********************************************************************/
  60. /* header files */
  61. #include "df220_defs.h"
  62. /*********************************************************************/
  63. /* (extern) variable declarations */
  64. /*********************************************************************/
  65. /* function prototype declarations */
  66. /*!
  67. * @brief This API is the entry point, Call this API before using other APIs.
  68. * This API reads the chip-id of the sensor which is the first step to
  69. * verify the sensor and also it configures the read mechanism of SPI and
  70. * I2C interface.
  71. *
  72. * @param[in,out] dev : Structure instance of df220_dev
  73. *
  74. * @return Result of API execution status
  75. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  76. */
  77. int8_t df220_init(struct df220_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 df220_dev.
  87. *
  88. * @return Result of API execution status
  89. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  90. */
  91. int8_t df220_set_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct df220_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 df220_dev.
  99. *
  100. * @note For most of the registers auto address increment applies, with the
  101. * exception of a few special registers, which trap the address. For e.g.,
  102. * Register address - 0x14(DF220_FIFO_DATA_ADDR)
  103. *
  104. * @return Result of API execution status
  105. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  106. */
  107. int8_t df220_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, const struct df220_dev *dev);
  108. /*!
  109. * @brief This API is used to perform soft-reset of the sensor
  110. * where all the registers are reset to their default values except 0x4B.
  111. *
  112. * @param[in] dev : Structure instance of df220_dev.
  113. *
  114. * @return Result of API execution status
  115. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  116. */
  117. int8_t df220_soft_reset(const struct df220_dev *dev);
  118. /*!
  119. * @brief This API is used to set the power mode of the sensor.
  120. *
  121. * @param[in] power_mode : Macro to select power mode of the sensor.
  122. * @param[in] dev : Structure instance of df220_dev.
  123. *
  124. * Possible value for power_mode :
  125. * - DF220_NORMAL_MODE
  126. * - DF220_SLEEP_MODE
  127. * - DF220_LOW_POWER_MODE
  128. *
  129. * @return Result of API execution status
  130. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  131. */
  132. int8_t df220_set_power_mode(uint8_t power_mode, const struct df220_dev *dev);
  133. /*!
  134. * @brief This API is used to get the power mode of the sensor
  135. *
  136. * @param[out] power_mode : power mode of the sensor.
  137. * @param[in] dev : Structure instance of df220_dev.
  138. *
  139. * * Possible value for power_mode :
  140. * - DF220_NORMAL_MODE
  141. * - DF220_SLEEP_MODE
  142. * - DF220_LOW_POWER_MODE
  143. *
  144. * @return Result of API execution status
  145. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  146. */
  147. int8_t df220_get_power_mode(uint8_t *power_mode, const struct df220_dev *dev);
  148. /*!
  149. * @brief This API is used to get the force data along with the sensor-time
  150. *
  151. * @param[in,out] force : Structure instance to store data
  152. * @param[in] dev : Structure instance of df220_dev
  153. *
  154. *
  155. * @note : The Force data value are in LSB based on the range selected
  156. *
  157. * @return Result of API execution status
  158. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  159. */
  160. int8_t df220_get_force_data(struct df220_sensor_data *force, const struct df220_dev *dev);
  161. /*!
  162. * @brief This API is used to set the sensor settings like sensor
  163. * configurations and interrupt configurations like
  164. * - Force sensor configurations (Like ODR,OSR,range...)
  165. * - Tap configurations
  166. * - Activity change configurations
  167. * - Gen1/Gen2 configurations
  168. * - Orient change configurations
  169. * - Step counter configurations
  170. *
  171. * @param[in] conf : Structure instance of the configuration structure
  172. * @param[in] n_sett : Number of settings to be set
  173. * @param[in] dev : Structure instance of df220_dev
  174. *
  175. * @note : Fill in the value of the required configurations in the conf structure
  176. * (Examples are mentioned in the readme.md) before calling this API
  177. *
  178. * @return Result of API execution status
  179. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  180. */
  181. int8_t df220_set_sensor_conf(const struct df220_sensor_conf *conf, uint16_t n_sett, const struct df220_dev *dev);
  182. /*!
  183. * @brief This API is used to get the sensor settings like sensor
  184. * configurations and interrupt configurations and store
  185. * them in the corresponding structure instance
  186. *
  187. * @param[in] conf : Structure instance of the configuration structure
  188. * @param[in] n_sett : Number of settings to be obtained
  189. * @param[in] dev : Structure instance of df220_dev.
  190. *
  191. * @note : Call the API and the settings structure will be updated with the
  192. * sensor settings
  193. *
  194. * @return Result of API execution status
  195. * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
  196. */
  197. int8_t df220_get_sensor_conf(struct df220_sensor_conf *conf, uint16_t n_sett, const struct df220_dev *dev);
  198. #ifdef __cplusplus
  199. }
  200. #endif /* End of CPP guard */
  201. #endif /* DF220_H__ */
  202. /** @}*/