• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: Provides V150 HAL GPIO \n
16  *
17  * History: \n
18  * 2022-07-27, Create file. \n
19  */
20 
21 #ifndef HAL_GPIO_V150_H
22 #define HAL_GPIO_V150_H
23 
24 #include "hal_gpio.h"
25 #include "hal_gpio_v150_regs_op.h"
26 #include "hal_gpio_v150_comm.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 #endif /* __cplusplus */
33 
34 /**
35  * @defgroup drivers_hal_gpio_v150 GPIO V150
36  * @ingroup  drivers_hal_gpio
37  * @{
38  */
39 
40 /**
41  * @if Eng
42  * @brief  GPIO LEVEL.
43  * @else
44  * @brief  GPIO高低电平。
45  * @endif
46  */
47 typedef enum hal_gpio_level {
48     HAL_GPIO_LEVEL_LOW,
49     HAL_GPIO_LEVEL_HIGH,
50 } hal_gpio_level_t;
51 
52 /**
53  * @if Eng
54  * @brief  GPIO directions.
55  * @else
56  * @brief  GPIO输入输出方向。
57  * @endif
58  */
59 typedef enum hal_gpio_direction {
60     HAL_GPIO_DIRECTION_OUTPUT,
61     HAL_GPIO_DIRECTION_INPUT
62 } hal_gpio_direction_t;
63 
64 /**
65  * @if Eng
66  * @brief  GPIO ctrl mode.
67  * @else
68  * @brief  GPIO控制模式。
69  * @endif
70  */
71 typedef enum hal_gpio_ctrl_mode {
72     HAL_GPIO_CTRL_MODE_SW,
73     HAL_GPIO_CTRL_MODE_HW
74 } hal_gpio_ctrl_mode_t;
75 
76 /**
77  * @if Eng
78  * @brief  GPIO interrupt enable.
79  * @else
80  * @brief  GPIO中断使能。
81  * @endif
82  */
83 typedef enum hal_gpio_intr_enable {
84     HAL_GPIO_INTR_DISABLE,
85     HAL_GPIO_INTR_ENABLE
86 } hal_gpio_intr_enable_t;
87 
88 /**
89  * @if Eng
90  * @brief  GPIO interrupt mask.
91  * @else
92  * @brief  GPIO中断屏蔽。
93  * @endif
94  */
95 typedef enum hal_gpio_intr_mask {
96     HAL_GPIO_INTR_UNMASK,
97     HAL_GPIO_INTR_MASK
98 } hal_gpio_intr_mask_t;
99 
100 /**
101  * @if Eng
102  * @brief  GPIO debounce enable/disable.
103  * @else
104  * @brief  GPIO去毛刺使能或去使能。
105  * @endif
106  */
107 typedef enum hal_gpio_debounce {
108     HAL_GPIO_DEBOUNCE_DISABLED,     /*!< @if Eng GPIO debounce disabled.
109                                          @else   GPIO去毛刺不使能。 @endif */
110     HAL_GPIO_DEBOUNCE_ENABLED,      /*!< @if Eng GPIO debounce enabled.
111                                          @else   GPIO去毛刺使能。 @endif */
112 } hal_gpio_debounce_t;
113 
114 /**
115  * @if Eng
116  * @brief  GPIO debounce enable/disable.
117  * @else
118  * @brief  GPIO中断清除。
119  * @endif
120  */
121 typedef enum hal_gpio_intr_clr {
122     HAL_GPIO_INTR_NOT_CLEAR,        /*!< @if Eng GPIO interrupt not clear.
123                                          @else   GPIO中断不清除。 @endif */
124     HAL_GPIO_INTR_CLEAR,            /*!< @if Eng GPIO interrupt clear.
125                                          @else   GPIO中断清除。 @endif */
126 } hal_gpio_intr_clr_t;
127 
128 
129 /**
130  * @if Eng
131  * @brief  Handler of the GPIO interrupt request.
132  * @else
133  * @brief  GPIO中断处理函数。
134  * @endif
135  */
136 void hal_gpio_v150_irq_handler(void);
137 
138 /**
139  * @if Eng
140  * @brief  Get the context of current module, see @ref gpio_context_t.
141  * @return The context of GPIO module, see @ref gpio_context_t.
142  * @else
143  * @brief  获取当前模块的上下文描述,参考 @ref gpio_context_t 。
144  * @return 当前模块的上下文描述,参考 @ref gpio_context_t 。
145  * @endif
146  */
147 gpio_context_t *gpio_v150_context_get(void);
148 
149 /**
150  * @if Eng
151  * @brief  Get the HAL context of current module, see @ref hal_gpio_context_t.
152  * @return The HAL context of GPIO module, see @ref hal_gpio_context_t.
153  * @else
154  * @brief  获取当前HAL层模块的上下文描述,参考 @ref hal_gpio_context_t 。
155  * @return 当前HAL层模块的上下文描述,参考 @ref hal_gpio_context_t 。
156  * @endif
157  */
158 hal_gpio_context_t *hal_gpio_v150_context_get(void);
159 
160 /**
161  * @if Eng
162  * @brief  HAL GPIO init interface.
163  * @retval ERRCODE_SUCC   Success.
164  * @retval Other        Failure. For details, see @ref errcode_t.
165  * @else
166  * @brief  HAL层GPIO的初始化接口。
167  * @retval ERRCODE_SUCC 成功。
168  * @retval Other        失败,参考 @ref errcode_t 。
169  * @endif
170  */
171 void hal_gpio_v150_init(void);
172 
173 /**
174  * @if Eng
175  * @brief  HAL GPIO deinit interface.
176  * @retval ERRCODE_SUCC   Success.
177  * @retval Other        Failure. For details, see @ref errcode_t.
178  * @else
179  * @brief  HAL层GPIO去初始化接口。
180  * @retval ERRCODE_SUCC 成功。
181  * @retval Other        失败,参考 @ref errcode_t 。
182  * @endif
183  */
184 void hal_gpio_v150_deinit(void);
185 
186 /**
187  * @if Eng
188  * @brief  HAL GPIO setdir device interface.
189  * @param  [in]  pin PIN to use. see @ref pin_t.
190  * @param  [in]  dir Input or output direction. see @ref gpio_direction_t.
191  * @retval ERRCODE_SUCC   Success.
192  * @retval Other        Failure. For details, see @ref errcode_t.
193  * @else
194  * @brief  HAL层GPIO设置输入输出方向接口。
195  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
196  * @param  [in]  dir 输入输出方向, 参考 @ref gpio_direction_t 。
197  * @retval ERRCODE_SUCC 成功。
198  * @retval Other        失败,参考 @ref errcode_t 。
199  * @endif
200  */
201 errcode_t hal_gpio_v150_setdir(pin_t pin, gpio_direction_t dir);
202 
203 /**
204  * @if Eng
205  * @brief  HAL GPIO setdir device interface.
206  * @param  [in]  pin PIN to use. see @ref pin_t.
207  * @retval GPIO input or output direction.
208  * @else
209  * @brief  HAL层GPIO获取输入输出方向接口。
210  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
211  * @retval GPIO输入输出方向 。
212  * @endif
213  */
214 gpio_direction_t hal_gpio_v150_getdir(pin_t pin);
215 
216 /**
217  * @if Eng
218  * @brief  HAL GPIO control interface.
219  * @param  [in]  pin PIN to use. see @ref pin_t
220  * @param  [in]  id ID of the GPIO control.
221  * @retval ERRCODE_SUCC   Success.
222  * @retval Other        Failure. For details, see @ref errcode_t.
223  * @else
224  * @brief  HAL层GPIO控制接口。
225  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
226  * @param  [in]  id GPIO控制请求ID。
227  * @retval ERRCODE_SUCC 成功。
228  * @retval Other        失败,参考 @ref errcode_t 。
229  * @endif
230  */
231 errcode_t hal_gpio_v150_ctrl(pin_t pin, hal_gpio_ctrl_id_t id);
232 
233 /**
234  * @if Eng
235  * @brief  HAL GPIO output interface.
236  * @param  [in]  pin PIN to use. see @ref pin_t.
237  * @param  [in]  level  Set to HIGH or LOW the output of a GPIO previously claimed for output. see @ref gpio_level_t.
238  * @retval ERRCODE_SUCC   Success.
239  * @retval Other        Failure. For details, see @ref errcode_t.
240  * @else
241  * @brief  HAL层GPIO的output接口 。
242  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
243  * @param  [in]  level 设置output输出HIGH or LOW,参考 @ref gpio_level_t 。
244  * @retval ERRCODE_SUCC 成功。
245  * @retval Other        失败,参考 @ref errcode_t 。
246  * @endif
247  */
248 errcode_t hal_gpio_v150_output(pin_t pin, gpio_level_t level);
249 
250 /**
251  * @if Eng
252  * @brief  HAL GPIO get output value interface.
253  * @param  [in]  pin PIN to use. see @ref pin_t.
254  * @retval GPIO output level value(high or low).
255  * @else
256  * @brief  HAL层获取GPIO的output值接口 。
257  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
258  * @retval GPIO输出电平值 。
259  * @endif
260  */
261 gpio_level_t hal_gpio_v150_get_outval(pin_t pin);
262 
263 /**
264  * @if Eng
265  * @brief  HAL GPIO get input level interface.
266  * @param  [in]  pin PIN to use. see @ref pin_t.
267  * @retval GPIO level, see @ref gpio_level_t.
268  * @else
269  * @brief  HAL层GPIO的input接口 。
270  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
271  * @retval GPIO电平,参考 @ref gpio_level_t 。
272  * @endif
273  */
274 gpio_level_t hal_gpio_v150_get_inval(pin_t pin);
275 
276 /**
277  * @if Eng
278  * @brief  HAL GPIO register a callback for the PIN.
279  * @param  [in]  pin PIN to use. see @ref pin_t.
280  * @param  [in]  trigger Trigger under which the callback will be invoked.
281  * @param  [in]  callback Pointer to callback. see @ref gpio_callback_t.
282  * @param  [in]  need_callback Whether callback is needed.
283  * @retval ERRCODE_SUCC   Success.
284  * @retval Other        Failure. For details, see @ref errcode_t.
285  * @else
286  * @brief  HAL层GPIO的注册中断接口。
287  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
288  * @param  [in]  trigger 触发回调的触发器。
289  * @param  [in]  callback 指向回调的指针,参考 @ref gpio_callback_t 。
290  * @param  [in]  need_callback 是否需要回调 。
291  * @retval ERRCODE_SUCC 成功。
292  * @retval Other        失败,参考 @ref errcode_t 。
293  * @endif
294  */
295 errcode_t hal_gpio_v150_register(pin_t pin, uint32_t trigger, gpio_callback_t callback, bool need_callback);
296 
297 /**
298  * @if Eng
299  * @brief  HAL GPIO unregister a callback for the PIN.
300  * @param  [in]  pin PIN to use. see @ref pin_t.
301  * @retval ERRCODE_SUCC   Success.
302  * @retval Other        Failure. For details, see @ref errcode_t.
303  * @else
304  * @brief  HAL层GPIO的注册中断接口。
305  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
306  * @retval ERRCODE_SUCC 成功。
307  * @retval Other        失败,参考 @ref errcode_t 。
308  * @endif
309  */
310 errcode_t hal_gpio_v150_unregister(pin_t pin);
311 
312 /**
313  * @}
314  */
315 
316 #ifdef __cplusplus
317 #if __cplusplus
318 }
319 #endif /* __cplusplus */
320 #endif /* __cplusplus */
321 
322 #endif
323