• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
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 #ifndef __HAL_GPIO_H__
16 #define __HAL_GPIO_H__
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include "plat_types.h"
23 #include "hal_iomux.h"
24 
25 enum HAL_GPIO_DIR_T {
26     HAL_GPIO_DIR_IN = 0,
27     HAL_GPIO_DIR_OUT = 1,
28 };
29 
30 enum HAL_GPIO_IRQ_TYPE_T {
31     HAL_GPIO_IRQ_TYPE_LEVEL_SENSITIVE = 0,
32     HAL_GPIO_IRQ_TYPE_EDGE_SENSITIVE,
33 };
34 
35 enum HAL_GPIO_IRQ_POLARITY_T {
36     HAL_GPIO_IRQ_POLARITY_LOW_FALLING = 0,
37     HAL_GPIO_IRQ_POLARITY_HIGH_RISING,
38 };
39 
40 typedef void (* HAL_GPIO_PIN_IRQ_HANDLER)(enum HAL_GPIO_PIN_T pin);
41 
42 struct HAL_GPIO_IRQ_CFG_T {
43     uint8_t irq_enable:1;
44     uint8_t irq_debounce:1;
45     enum HAL_GPIO_IRQ_TYPE_T irq_type;
46     enum HAL_GPIO_IRQ_POLARITY_T irq_polarity;
47     HAL_GPIO_PIN_IRQ_HANDLER irq_handler;
48 };
49 
50 enum HAL_GPIO_DIR_T hal_gpio_pin_get_dir(enum HAL_GPIO_PIN_T pin);
51 void hal_gpio_pin_set_dir(enum HAL_GPIO_PIN_T pin, enum HAL_GPIO_DIR_T dir, uint8_t val_for_out);
52 void hal_gpio_pin_set(enum HAL_GPIO_PIN_T pin);
53 void hal_gpio_pin_clr(enum HAL_GPIO_PIN_T pin);
54 uint8_t hal_gpio_pin_get_val(enum HAL_GPIO_PIN_T pin);
55 uint8_t hal_gpio_setup_irq(enum HAL_GPIO_PIN_T pin, const struct HAL_GPIO_IRQ_CFG_T *cfg);
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif
62