2 **************************************************************************
3 * @file at32f435_437_acc.c
4 * @brief contains all the functions for the acc firmware library
5 **************************************************************************
6 * Copyright notice & Disclaimer
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.
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.
22 **************************************************************************
25 #include "at32f435_437_conf.h"
27 /** @addtogroup AT32F435_437_periph_driver
32 * @brief ACC driver modules
36 #ifdef ACC_MODULE_ENABLED
38 /** @defgroup ACC_private_functions
43 * @brief enable or disable the acc calibration mode.
44 * @param acc_trim: specifies the acc calibration type.
45 * this parameter can be one of the following values:
48 * @param new_state: specifies the acc calibration to be enabled or disabled.(TRUE or FALSE)
51 void acc_calibration_mode_enable(uint16_t acc_trim
, confirm_state new_state
)
53 if(acc_trim
== ACC_CAL_HICKCAL
)
55 ACC_REGS
->ctrl1_bit
.entrim
= FALSE
;
59 ACC_REGS
->ctrl1_bit
.entrim
= TRUE
;
61 ACC_REGS
->ctrl1_bit
.calon
= new_state
;
65 * @brief store calibration step data in acc's ctrl1 register.
66 * @param step_value: value to be stored in the acc's ctrl1 register
69 void acc_step_set(uint8_t step_value
)
71 ACC_REGS
->ctrl1_bit
.step
= step_value
;
75 * @brief select sof sourse for acc in acc's ctrl1 register.
76 * @param sof_sel: value to be stored in the acc's ctrl1 register
77 * this parameter can be one of the following values:
82 void acc_sof_select(uint16_t sof_sel
)
84 ACC_REGS
->ctrl1
|= sof_sel
;
88 * @brief enable or disable the specified acc interrupts.
89 * @param acc_int: specifies the acc interrupt sources to be enabled or disabled.
90 * this parameter can be one of the following values:
93 * @param new_state (TRUE or FALSE)
96 void acc_interrupt_enable(uint16_t acc_int
, confirm_state new_state
)
98 if(acc_int
== ACC_CALRDYIEN_INT
)
100 ACC_REGS
->ctrl1_bit
.calrdyien
= new_state
;
104 ACC_REGS
->ctrl1_bit
.eien
= new_state
;
109 * @brief return the current acc hicktrim value.
111 * @retval 8-bit hicktrim value.
113 uint8_t acc_hicktrim_get(void)
115 return ((uint8_t)(ACC_REGS
->ctrl2_bit
.hicktrim
));
119 * @brief return the current acc hickcal value.
121 * @retval 8-bit hicktrim value.
123 uint8_t acc_hickcal_get(void)
125 return ((uint8_t)(ACC_REGS
->ctrl2_bit
.hickcal
));
129 * @brief wtire the value to acc c1 register.
130 * @param acc_c1_value
133 void acc_write_c1(uint16_t acc_c1_value
)
135 ACC_REGS
->c1
= acc_c1_value
;
139 * @brief wtire the value to acc c2 register.
140 * @param acc_c2_value
143 void acc_write_c2(uint16_t acc_c2_value
)
145 ACC_REGS
->c2
= acc_c2_value
;
149 * @brief wtire the value to acc c3 register.
150 * @param acc_c3_value
153 void acc_write_c3(uint16_t acc_c3_value
)
155 ACC_REGS
->c3
= acc_c3_value
;
159 * @brief return the current acc c1 value.
161 * @retval 16-bit c1 value.
163 uint16_t acc_read_c1(void)
165 return ((uint16_t)(ACC_REGS
->c1
));
169 * @brief return the current acc c2 value.
171 * @retval 16-bit c2 value.
173 uint16_t acc_read_c2(void)
175 return ((uint16_t)(ACC_REGS
->c2
));
179 * @brief return the current acc c3 value.
181 * @retval 16-bit c3 value.
183 uint16_t acc_read_c3(void)
185 return ((uint16_t)(ACC_REGS
->c3
));
189 * @brief check whether the specified acc flag is set or not.
190 * @param acc_flag: specifies the flag to check.
191 * this parameter can be one of the following values:
194 * @retval flag_status (SET or RESET)
196 flag_status
acc_flag_get(uint16_t acc_flag
)
198 if(acc_flag
== ACC_CALRDY_FLAG
)
199 return (flag_status
)(ACC_REGS
->sts_bit
.calrdy
);
201 return (flag_status
)(ACC_REGS
->sts_bit
.rslost
);
205 * @brief clear the specified acc flag is set or not.
206 * @param acc_flag: specifies the flag to check.
207 * this parameter can be any combination of the following values:
212 void acc_flag_clear(uint16_t acc_flag
)
214 ACC_REGS
->sts
= ~acc_flag
;