at32f413_acc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. **************************************************************************
  3. * @file at32f413_acc.c
  4. * @brief contains all the functions for the acc firmware library
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #include "at32f413_conf.h"
  25. /** @addtogroup AT32F413_periph_driver
  26. * @{
  27. */
  28. /** @defgroup ACC
  29. * @brief ACC driver modules
  30. * @{
  31. */
  32. #ifdef ACC_MODULE_ENABLED
  33. /** @defgroup ACC_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief enable or disable the acc calibration mode.
  38. * @param acc_trim: specifies the acc calibration type.
  39. * this parameter can be one of the following values:
  40. * - ACC_CAL_HICKCAL
  41. * - ACC_CAL_HICKTRIM
  42. * @param new_state: specifies the acc calibration to be enabled or disabled.(TRUE or FALSE)
  43. * @retval none
  44. */
  45. void acc_calibration_mode_enable(uint16_t acc_trim, confirm_state new_state)
  46. {
  47. if(acc_trim == ACC_CAL_HICKCAL)
  48. {
  49. ACC->ctrl1_bit.entrim = FALSE;
  50. }
  51. else
  52. {
  53. ACC->ctrl1_bit.entrim = TRUE;
  54. }
  55. ACC->ctrl1_bit.calon = new_state;
  56. }
  57. /**
  58. * @brief store calibration step data in acc's ctrl1 register.
  59. * @param step_value: value to be stored in the acc's ctrl1 register
  60. * @retval none
  61. */
  62. void acc_step_set(uint8_t step_value)
  63. {
  64. ACC->ctrl1_bit.step = step_value;
  65. }
  66. /**
  67. * @brief enable or disable the specified acc interrupts.
  68. * @param acc_int: specifies the acc interrupt sources to be enabled or disabled.
  69. * this parameter can be one of the following values:
  70. * - ACC_CALRDYIEN_INT
  71. * - ACC_EIEN_INT
  72. * @param new_state (TRUE or FALSE)
  73. * @retval none
  74. */
  75. void acc_interrupt_enable(uint16_t acc_int, confirm_state new_state)
  76. {
  77. if(acc_int == ACC_CALRDYIEN_INT)
  78. {
  79. ACC->ctrl1_bit.calrdyien = new_state;
  80. }
  81. else
  82. {
  83. ACC->ctrl1_bit.eien = new_state;
  84. }
  85. }
  86. /**
  87. * @brief return the current acc hicktrim value.
  88. * @param none
  89. * @retval 8-bit hicktrim value.
  90. */
  91. uint8_t acc_hicktrim_get(void)
  92. {
  93. return ((uint8_t)(ACC->ctrl2_bit.hicktrim));
  94. }
  95. /**
  96. * @brief return the current acc hickcal value.
  97. * @param none
  98. * @retval 8-bit hicktrim value.
  99. */
  100. uint8_t acc_hickcal_get(void)
  101. {
  102. return ((uint8_t)(ACC->ctrl2_bit.hickcal));
  103. }
  104. /**
  105. * @brief wtire the value to acc c1 register.
  106. * @param acc_c1_value
  107. * @retval none.
  108. */
  109. void acc_write_c1(uint16_t acc_c1_value)
  110. {
  111. ACC->c1 = acc_c1_value;
  112. }
  113. /**
  114. * @brief wtire the value to acc c2 register.
  115. * @param acc_c2_value
  116. * @retval none.
  117. */
  118. void acc_write_c2(uint16_t acc_c2_value)
  119. {
  120. ACC->c2 = acc_c2_value;
  121. }
  122. /**
  123. * @brief wtire the value to acc c3 register.
  124. * @param acc_c3_value
  125. * @retval none.
  126. */
  127. void acc_write_c3(uint16_t acc_c3_value)
  128. {
  129. ACC->c3 = acc_c3_value;
  130. }
  131. /**
  132. * @brief return the current acc c1 value.
  133. * @param none
  134. * @retval 16-bit c1 value.
  135. */
  136. uint16_t acc_read_c1(void)
  137. {
  138. return ((uint16_t)(ACC->c1));
  139. }
  140. /**
  141. * @brief return the current acc c2 value.
  142. * @param none
  143. * @retval 16-bit c2 value.
  144. */
  145. uint16_t acc_read_c2(void)
  146. {
  147. return ((uint16_t)(ACC->c2));
  148. }
  149. /**
  150. * @brief return the current acc c3 value.
  151. * @param none
  152. * @retval 16-bit c3 value.
  153. */
  154. uint16_t acc_read_c3(void)
  155. {
  156. return ((uint16_t)(ACC->c3));
  157. }
  158. /**
  159. * @brief check whether the specified acc flag is set or not.
  160. * @param acc_flag: specifies the flag to check.
  161. * this parameter can be one of the following values:
  162. * - ACC_RSLOST_FLAG
  163. * - ACC_CALRDY_FLAG
  164. * @retval flag_status (SET or RESET)
  165. */
  166. flag_status acc_flag_get(uint16_t acc_flag)
  167. {
  168. if(acc_flag == ACC_CALRDY_FLAG)
  169. return (flag_status)(ACC->sts_bit.calrdy);
  170. else
  171. return (flag_status)(ACC->sts_bit.rslost);
  172. }
  173. /**
  174. * @brief clear the specified acc flag is set or not.
  175. * @param acc_flag: specifies the flag to check.
  176. * this parameter can be any combination of the following values:
  177. * - ACC_RSLOST_FLAG
  178. * - ACC_CALRDY_FLAG
  179. * @retval none
  180. */
  181. void acc_flag_clear(uint16_t acc_flag)
  182. {
  183. ACC->sts = ~acc_flag;
  184. }
  185. /**
  186. * @}
  187. */
  188. #endif
  189. /**
  190. * @}
  191. */
  192. /**
  193. * @}
  194. */