before merging master
[inav.git] / lib / main / AT32F43x / Drivers / AT32F43x_StdPeriph_Driver / src / at32f435_437_acc.c
blob18afcc3bae52ac4a3e636bdaabd7b3fbbdb5ccd9
1 /**
2 **************************************************************************
3 * @file at32f435_437_acc.c
4 * @version v2.1.0
5 * @date 2022-08-16
6 * @brief contains all the functions for the acc firmware library
7 **************************************************************************
8 * Copyright notice & Disclaimer
10 * The software Board Support Package (BSP) that is made available to
11 * download from Artery official website is the copyrighted work of Artery.
12 * Artery authorizes customers to use, copy, and distribute the BSP
13 * software and its related documentation for the purpose of design and
14 * development in conjunction with Artery microcontrollers. Use of the
15 * software is governed by this copyright notice and the following disclaimer.
17 * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
18 * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
19 * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
20 * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
21 * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 **************************************************************************
27 #include "at32f435_437_conf.h"
29 /** @addtogroup AT32F435_437_periph_driver
30 * @{
33 /** @defgroup ACC
34 * @brief ACC driver modules
35 * @{
38 #ifdef ACC_MODULE_ENABLED
40 /** @defgroup ACC_private_functions
41 * @{
44 /**
45 * @brief enable or disable the acc calibration mode.
46 * @param acc_trim: specifies the acc calibration type.
47 * this parameter can be one of the following values:
48 * - ACC_CAL_HICKCAL
49 * - ACC_CAL_HICKTRIM
50 * @param new_state: specifies the acc calibration to be enabled or disabled.(TRUE or FALSE)
51 * @retval none
53 void acc_calibration_mode_enable(uint16_t acc_trim, confirm_state new_state)
55 if(acc_trim == ACC_CAL_HICKCAL)
57 ACC->ctrl1_bit.entrim = FALSE;
59 else
61 ACC->ctrl1_bit.entrim = TRUE;
63 ACC->ctrl1_bit.calon = new_state;
66 /**
67 * @brief store calibration step data in acc's ctrl1 register.
68 * @param step_value: value to be stored in the acc's ctrl1 register
69 * @retval none
71 void acc_step_set(uint8_t step_value)
73 ACC->ctrl1_bit.step = step_value;
76 /**
77 * @brief select sof sourse for acc in acc's ctrl1 register.
78 * @param sof_sel: value to be stored in the acc's ctrl1 register
79 * this parameter can be one of the following values:
80 * @arg ACC_SOF_OTG1
81 * @arg ACC_SOF_OTG2
82 * @retval none
84 void acc_sof_select(uint16_t sof_sel)
86 ACC->ctrl1 |= sof_sel;
89 /**
90 * @brief enable or disable the specified acc interrupts.
91 * @param acc_int: specifies the acc interrupt sources to be enabled or disabled.
92 * this parameter can be one of the following values:
93 * - ACC_CALRDYIEN_INT
94 * - ACC_EIEN_INT
95 * @param new_state (TRUE or FALSE)
96 * @retval none
98 void acc_interrupt_enable(uint16_t acc_int, confirm_state new_state)
100 if(acc_int == ACC_CALRDYIEN_INT)
102 ACC->ctrl1_bit.calrdyien = new_state;
104 else
106 ACC->ctrl1_bit.eien = new_state;
111 * @brief return the current acc hicktrim value.
112 * @param none
113 * @retval 8-bit hicktrim value.
115 uint8_t acc_hicktrim_get(void)
117 return ((uint8_t)(ACC->ctrl2_bit.hicktrim));
121 * @brief return the current acc hickcal value.
122 * @param none
123 * @retval 8-bit hicktrim value.
125 uint8_t acc_hickcal_get(void)
127 return ((uint8_t)(ACC->ctrl2_bit.hickcal));
131 * @brief wtire the value to acc c1 register.
132 * @param acc_c1_value
133 * @retval none.
135 void acc_write_c1(uint16_t acc_c1_value)
137 ACC->c1 = acc_c1_value;
141 * @brief wtire the value to acc c2 register.
142 * @param acc_c2_value
143 * @retval none.
145 void acc_write_c2(uint16_t acc_c2_value)
147 ACC->c2 = acc_c2_value;
151 * @brief wtire the value to acc c3 register.
152 * @param acc_c3_value
153 * @retval none.
155 void acc_write_c3(uint16_t acc_c3_value)
157 ACC->c3 = acc_c3_value;
161 * @brief return the current acc c1 value.
162 * @param none
163 * @retval 16-bit c1 value.
165 uint16_t acc_read_c1(void)
167 return ((uint16_t)(ACC->c1));
171 * @brief return the current acc c2 value.
172 * @param none
173 * @retval 16-bit c2 value.
175 uint16_t acc_read_c2(void)
177 return ((uint16_t)(ACC->c2));
181 * @brief return the current acc c3 value.
182 * @param none
183 * @retval 16-bit c3 value.
185 uint16_t acc_read_c3(void)
187 return ((uint16_t)(ACC->c3));
191 * @brief check whether the specified acc flag is set or not.
192 * @param acc_flag: specifies the flag to check.
193 * this parameter can be one of the following values:
194 * - ACC_RSLOST_FLAG
195 * - ACC_CALRDY_FLAG
196 * @retval flag_status (SET or RESET)
198 flag_status acc_flag_get(uint16_t acc_flag)
200 if(acc_flag == ACC_CALRDY_FLAG)
201 return (flag_status)(ACC->sts_bit.calrdy);
202 else
203 return (flag_status)(ACC->sts_bit.rslost);
207 * @brief clear the specified acc flag is set or not.
208 * @param acc_flag: specifies the flag to check.
209 * this parameter can be any combination of the following values:
210 * - ACC_RSLOST_FLAG
211 * - ACC_CALRDY_FLAG
212 * @retval none
214 void acc_flag_clear(uint16_t acc_flag)
216 ACC->sts = ~acc_flag;
220 * @}
223 #endif
226 * @}
230 * @}