• 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 GPIO driver api \n
16  *
17  * History: \n
18  * 2022-07-27, Create file. \n
19  */
20 #ifndef GPIO_H
21 #define GPIO_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 #include "platform_core.h"
26 #include "hal_gpio.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 #endif /* __cplusplus */
33 
34 /**
35  * @defgroup drivers_driver_gpio GPIO
36  * @ingroup  drivers_driver
37  * @{
38  */
39 
40 /**
41  * @if Eng
42  * @brief  Initialize the GPIO.
43  * @note   This function should be called before any other on in the module.
44  * @else
45  * @brief  初始化GPIO。
46  * @note   这个回调函数应该在所有函数之前执行。
47  * @endif
48  */
49 void uapi_gpio_init(void);
50 
51 /**
52  * @if Eng
53  * @brief  Deinitialize the GPIO.
54  * @else
55  * @brief  去初始化GPIO.
56  * @endif
57  */
58 void uapi_gpio_deinit(void);
59 
60 /**
61  * @if Eng
62  * @brief  Set the GPIO direction.
63  * @param  [in]  pin IO, see @ref pin_t.
64  * @param  [in]  dir Input or output direction, see @ref gpio_direction_t.
65  * @retval ERRCODE_SUCC Success.
66  * @retval Other        Failure. For details, see @ref errcode_t.
67  * @else
68  * @brief  设置GPIO的输入输出方向函数。
69  * @param  [in] pin IO, 参考 @ref pin_t 。
70  * @param  [in] dir 输入输出方向, 参考 @ref gpio_direction_t 。
71  * @retval ERRCODE_SUCC 成功。
72  * @retval Other        失败,参考 @ref errcode_t 。
73  * @endif
74  */
75 errcode_t uapi_gpio_set_dir(pin_t pin, gpio_direction_t dir);
76 
77 /**
78  * @if Eng
79  * @brief  Get the GPIO direction.
80  * @param  [in]  pin IO, see @ref pin_t.
81  * @retval GPIO Input or output direction.
82  * @else
83  * @brief  获取GPIO的输入输出方向函数。
84  * @param  [in] pin IO, 参考 @ref pin_t 。
85  * @retval GPIO输入输出方向 。
86  * @endif
87  */
88 gpio_direction_t uapi_gpio_get_dir(pin_t pin);
89 
90 /**
91  * @if Eng
92  * @brief  Set the GPIO level.
93  * @param  [in]  pin IO, see @ref pin_t.
94  * @param  [in]  level The output as high or low, see @ref gpio_level_t.
95  * @retval ERRCODE_SUCC Success.
96  * @retval Other        Failure. For details, see @ref errcode_t.
97  * @else
98  * @brief  设置GPIO的输出状态。
99  * @param  [in]  pin IO, 参考 @ref pin_t 。
100  * @param  [in]  level GPIO 输出设置为高或低, 参考 @ref gpio_level_t 。
101  * @retval ERRCODE_SUCC 成功。
102  * @retval Other        失败,参考 @ref errcode_t 。
103  * @endif
104  */
105 errcode_t uapi_gpio_set_val(pin_t pin, gpio_level_t level);
106 
107 /**
108  * @if Eng
109  * @brief  HAL GPIO get output value interface.
110  * @param  [in]  pin PIN to use. see @ref pin_t.
111  * @retval GPIO output level value(high or low).
112  * @else
113  * @brief  HAL层获取GPIO的output值接口 。
114  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
115  * @retval GPIO输出电平值 。
116  * @endif
117  */
118 gpio_level_t uapi_gpio_get_output_val(pin_t pin);
119 
120 /**
121  * @if Eng
122  * @brief  Read the GPIO value.
123  * @param  [in]  pin IO, see @ref pin_t.
124  * @retval GPIO input level value.
125  * @else
126  * @brief  读取GPIO的输入状态。
127  * @param  [in]  pin IO, 参考 @ref pin_t 。
128  * @retval GPIO输入电平值。
129  * @endif
130  */
131 gpio_level_t uapi_gpio_get_val(pin_t pin);
132 
133 /**
134  * @if Eng
135  * @brief  Toggle the GPIO.
136  * @param  [in]  pin IO, see @ref pin_t.
137  * @retval ERRCODE_SUCC Success.
138  * @retval Other        Failure. For details, see @ref errcode_t.
139  * @else
140  * @brief  翻转输出GPIO电平状态.
141  * @param  [in]  pin IO, 参考 @ref pin_t 。
142  * @retval ERRCODE_SUCC 成功。
143  * @retval Other        失败,参考 @ref errcode_t 。
144  * @endif
145  */
146 errcode_t uapi_gpio_toggle(pin_t pin);
147 
148 /**
149  * @if Eng
150  * @brief  HAL GPIO set isr mode.
151  * @param  [in]  pin PIN to use. see @ref pin_t.
152  * @param  [in]  trigger Interrupt type of the GPIO:
153  *                       - 1 : Rising edge interrupt
154  *                       - 2 : Falling edge interrupt
155  *                       - 3 : Doublie edge interrupt
156  *                       - 4 : Low level interrupt
157  *                       - 8 : High level interrupt
158  * @retval ERRCODE_SUCC   Success.
159  * @retval Other        Failure. For details, see @ref errcode_t.
160  * @else
161  * @brief  HAL层GPIO设置中断模式。
162  * @param  [in]  pin io引脚, 参考 @ref pin_t 。
163  * @param  [in]  trigger GPIO中断类型:
164  *                       - 1 : 上升沿中断
165  *                       - 2 : 下降沿中断
166  *                       - 3 : 双边沿中断
167  *                       - 4 : 低电平中断
168  *                       - 8 : 高电平中断
169  * @retval ERRCODE_SUCC 成功。
170  * @retval Other        失败,参考 @ref errcode_t 。
171  * @endif
172  */
173 errcode_t uapi_gpio_set_isr_mode(pin_t pin, uint32_t trigger);
174 
175 /**
176  * @if Eng
177  * @brief  Clear the GPIO interrupt for the pin.
178  * @param  [in]  pin IO, see @ref pin_t.
179  * @param  [in]  trigger Interrupt type of the GPIO:
180  *                       - 1 : Rising edge interrupt
181  *                       - 2 : Falling edge interrupt
182  *                       - 3 : Doublie edge interrupt
183  *                       - 4 : Low level interrupt
184  *                       - 8 : High level interrupt
185  * @param  [in]  callback Pointer to callback, see @ref gpio_callback_t.
186  * @retval ERRCODE_SUCC Success.
187  * @retval Other        Failure. For details, see @ref errcode_t.
188  * @else
189  * @brief  注册GPIO的中断。
190  * @param  [in]  pin IO, 参考 @ref pin_t 。
191  * @param  [in]  trigger GPIO中断类型:
192  *                       - 1 : 上升沿中断
193  *                       - 2 : 下降沿中断
194  *                       - 3 : 双边沿中断
195  *                       - 4 : 低电平中断
196  *                       - 8 : 高电平中断
197  * @param  [in]  callback 指向回调的指针, 参考 @ref gpio_callback_t 。
198  * @retval ERRCODE_SUCC 成功。
199  * @retval Other        失败,参考 @ref errcode_t 。
200  * @endif
201  */
202 errcode_t uapi_gpio_register_isr_func(pin_t pin, uint32_t trigger, gpio_callback_t callback);
203 
204 /**
205  * @if Eng
206  * @brief  Unregister the GPIO interrupt for the pin.
207  * @param  [in]  pin IO, see @ref pin_t.
208  * @retval ERRCODE_SUCC Success.
209  * @retval Other        Failure. For details, see @ref errcode_t.
210  * @else
211  * @brief  去注册GPIO的中断。
212  * @param  [in]  pin IO, 参考 @ref pin_t 。
213  * @retval ERRCODE_SUCC 成功。
214  * @retval Other        失败,参考 @ref errcode_t 。
215  * @endif
216  */
217 errcode_t uapi_gpio_unregister_isr_func(pin_t pin);
218 
219 /**
220  * @if Eng
221  * @brief  Enable the GPIO interrupt for the pin.
222  * @param  [in]  pin IO, see @ref pin_t.
223  * @retval ERRCODE_SUCC Success.
224  * @retval Other        Failure. For details, see @ref errcode_t.
225  * @else
226  * @brief  使能GPIO指定端口的中断。
227  * @param  [in]  pin IO, 参考 @ref pin_t 。
228  * @retval ERRCODE_SUCC 成功。
229  * @retval Other        失败,参考 @ref errcode_t 。
230  * @endif
231  */
232 errcode_t uapi_gpio_enable_interrupt(pin_t pin);
233 
234 /**
235  * @if Eng
236  * @brief  Disable GPIO interrupt for the pin.
237  * @param  [in]  pin IO, see @ref pin_t.
238  * @retval ERRCODE_SUCC Success.
239  * @retval Other        Failure. For details, see @ref errcode_t.
240  * @else
241  * @brief  去使能GPIO指定端口的中断。
242  * @param  [in]  pin IO, 参考 @ref pin_t 。
243  * @retval ERRCODE_SUCC 成功。
244  * @retval Other        失败,参考 @ref errcode_t 。
245  * @endif
246  */
247 errcode_t uapi_gpio_disable_interrupt(pin_t pin);
248 
249 /**
250  * @if Eng
251  * @brief  Clear GPIO interrupt for the pin.
252  * @param  [in]  pin IO, see @ref pin_t.
253  * @retval ERRCODE_SUCC Success.
254  * @retval Other        Failure. For details, see @ref errcode_t.
255  * @else
256  * @brief  清除GPIO指定端口的中断。
257  * @param  [in]  pin IO, 参考 @ref pin_t 。
258  * @retval ERRCODE_SUCC 成功。
259  * @retval Other        失败,参考 @ref errcode_t 。
260  * @endif
261  */
262 errcode_t uapi_gpio_clear_interrupt(pin_t pin);
263 
264 #if defined(CONFIG_GPIO_SUPPORT_LPM)
265 /**
266  * @if Eng
267  * @brief  Suspend all of the GPIO channels.
268  * @param  [in]  arg Argument for suspend.
269  * @retval ERRCODE_SUCC Success.
270  * @retval Other        Failure. For details, see @ref errcode_t.
271  * @else
272  * @brief  挂起所有GPIO通道。
273  * @param  [in]  arg 挂起所需要的参数。
274  * @retval ERRCODE_SUCC 成功。
275  * @retval Other        失败,参考 @ref errcode_t 。
276  * @endif
277  */
278 errcode_t uapi_gpio_suspend(uintptr_t arg);
279 
280 /**
281  * @if Eng
282  * @brief  Resume all of the GPIO channels.
283  * @param  [in]  arg Argument for resume.
284  * @retval ERRCODE_SUCC Success.
285  * @retval Other        Failure. For details, see @ref errcode_t.
286  * @else
287  * @brief  恢复所有GPIO通道。
288  * @param  [in]  arg 恢复所需要的参数。
289  * @retval ERRCODE_SUCC 成功。
290  * @retval Other        失败,参考 @ref errcode_t 。
291  * @endif
292  */
293 errcode_t uapi_gpio_resume(uintptr_t arg);
294 #endif
295 
296 #if defined(CONFIG_GPIO_SELECT_CORE)
297 /**
298  * @if Eng
299  * @brief  GPIO select core.
300  * @else
301  * @brief  GPIO选择核心。
302  * @endif
303  */
304 void uapi_gpio_select_core(pin_t pin, cores_t core);
305 #endif
306 
307 /**
308  * @}
309  */
310 
311 #ifdef __cplusplus
312 #if __cplusplus
313 }
314 #endif /* __cplusplus */
315 #endif /* __cplusplus */
316 
317 #endif