2 **************************************************************************
3 * @file at32f435_437_acc.c
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
34 * @brief ACC driver modules
38 #ifdef ACC_MODULE_ENABLED
40 /** @defgroup ACC_private_functions
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:
50 * @param new_state: specifies the acc calibration to be enabled or disabled.(TRUE or FALSE)
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
;
61 ACC
->ctrl1_bit
.entrim
= TRUE
;
63 ACC
->ctrl1_bit
.calon
= new_state
;
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
71 void acc_step_set(uint8_t step_value
)
73 ACC
->ctrl1_bit
.step
= step_value
;
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:
84 void acc_sof_select(uint16_t sof_sel
)
86 ACC
->ctrl1
|= sof_sel
;
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:
95 * @param new_state (TRUE or FALSE)
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
;
106 ACC
->ctrl1_bit
.eien
= new_state
;
111 * @brief return the current acc hicktrim value.
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.
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
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
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
155 void acc_write_c3(uint16_t acc_c3_value
)
157 ACC
->c3
= acc_c3_value
;
161 * @brief return the current acc c1 value.
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.
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.
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:
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
);
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:
214 void acc_flag_clear(uint16_t acc_flag
)
216 ACC
->sts
= ~acc_flag
;