before merging master
[inav.git] / lib / main / AT32F43x / Drivers / AT32F43x_StdPeriph_Driver / src / at32f435_437_exint.c
blob31d55c0aff2fc5f5bf376549fba6445e45e0656c
1 /**
2 **************************************************************************
3 * @file at32f435_437_exint.c
4 * @version v2.1.0
5 * @date 2022-08-16
6 * @brief contains all the functions for the exint 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 EXINT
34 * @brief EXINT driver modules
35 * @{
38 #ifdef EXINT_MODULE_ENABLED
40 /** @defgroup EXINT_private_functions
41 * @{
44 /**
45 * @brief exint reset
46 * @param none
47 * @retval none
49 void exint_reset(void)
51 EXINT->inten = 0x00000000;
52 EXINT->polcfg1 = 0x00000000;
53 EXINT->polcfg2 = 0x00000000;
54 EXINT->evten = 0x00000000;
55 EXINT->intsts = 0x007FFFFF;
58 /**
59 * @brief exint default para init
60 * @param exint_struct
61 * - to the structure of exint_init_type
62 * @retval none
64 void exint_default_para_init(exint_init_type *exint_struct)
66 exint_struct->line_enable = FALSE;
67 exint_struct->line_select = EXINT_LINE_NONE;
68 exint_struct->line_polarity = EXINT_TRIGGER_FALLING_EDGE;
69 exint_struct->line_mode = EXINT_LINE_EVENT;
72 /**
73 * @brief exint init
74 * @param exint_struct
75 * - to the structure of exint_init_type
76 * @retval none
78 void exint_init(exint_init_type *exint_struct)
80 uint32_t line_index = 0;
81 line_index = exint_struct->line_select;
83 EXINT->inten &= ~line_index;
84 EXINT->evten &= ~line_index;
86 if(exint_struct->line_enable != FALSE)
88 if(exint_struct->line_mode == EXINT_LINE_INTERRUPUT)
90 EXINT->inten |= line_index;
92 else
94 EXINT->evten |= line_index;
97 EXINT->polcfg1 &= ~line_index;
98 EXINT->polcfg2 &= ~line_index;
99 if(exint_struct->line_polarity == EXINT_TRIGGER_RISING_EDGE)
101 EXINT->polcfg1 |= line_index;
103 else if(exint_struct->line_polarity == EXINT_TRIGGER_FALLING_EDGE)
105 EXINT->polcfg2 |= line_index;
107 else
109 EXINT->polcfg1 |= line_index;
110 EXINT->polcfg2 |= line_index;
116 * @brief clear exint flag
117 * @param exint_line
118 * this parameter can be any combination of the following values:
119 * - EXINT_LINE_0
120 * - EXINT_LINE_1
121 * ...
122 * - EXINT_LINE_21
123 * - EXINT_LINE_22
124 * @retval none
126 void exint_flag_clear(uint32_t exint_line)
128 EXINT->intsts = exint_line;
132 * @brief get exint flag
133 * @param exint_line
134 * this parameter can be one of the following values:
135 * - EXINT_LINE_0
136 * - EXINT_LINE_1
137 * ...
138 * - EXINT_LINE_21
139 * - EXINT_LINE_22
140 * @retval the new state of exint flag(SET or RESET).
142 flag_status exint_flag_get(uint32_t exint_line)
144 flag_status status = RESET;
145 uint32_t exint_flag =0;
146 exint_flag = EXINT->intsts & exint_line;
147 if((exint_flag != (uint16_t)RESET))
149 status = SET;
151 else
153 status = RESET;
155 return status;
159 * @brief generate exint software interrupt event
160 * @param exint_line
161 * this parameter can be one of the following values:
162 * - EXINT_LINE_0
163 * - EXINT_LINE_1
164 * ...
165 * - EXINT_LINE_21
166 * - EXINT_LINE_22
167 * @retval none
169 void exint_software_interrupt_event_generate(uint32_t exint_line)
171 EXINT->swtrg |= exint_line;
175 * @brief enable or disable exint interrupt
176 * @param exint_line
177 * this parameter can be any combination of the following values:
178 * - EXINT_LINE_0
179 * - EXINT_LINE_1
180 * ...
181 * - EXINT_LINE_21
182 * - EXINT_LINE_22
183 * @param new_state: new state of exint interrupt.
184 * this parameter can be: TRUE or FALSE.
185 * @retval none
187 void exint_interrupt_enable(uint32_t exint_line, confirm_state new_state)
189 if(new_state == TRUE)
191 EXINT->inten |= exint_line;
193 else
195 EXINT->inten &= ~exint_line;
200 * @brief enable or disable exint event
201 * @param exint_line
202 * this parameter can be any combination of the following values:
203 * - EXINT_LINE_0
204 * - EXINT_LINE_1
205 * ...
206 * - EXINT_LINE_21
207 * - EXINT_LINE_22
208 * @param new_state: new state of exint event.
209 * this parameter can be: TRUE or FALSE.
210 * @retval none
212 void exint_event_enable(uint32_t exint_line, confirm_state new_state)
214 if(new_state == TRUE)
216 EXINT->evten |= exint_line;
218 else
220 EXINT->evten &= ~exint_line;
225 * @}
228 #endif
231 * @}
235 * @}