• 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 port template \n
16  *
17  * History: \n
18  * 2022-07-26, Create file. \n
19  */
20 #ifndef GPIO_PORTING_H
21 #define GPIO_PORTING_H
22 
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include "platform_core.h"
26 #include "platform_types.h"
27 #include "hal_gpio_v150_comm_def.h"
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33 #endif /* __cplusplus */
34 
35 /**
36  * @defgroup drivers_port_gpio_v150 GPIO porting info.
37  * @ingroup  drivers_port_gpio
38  * @{
39  */
40 
41 /**
42  * @brief  GPIO info definition of each channel and group. Developer should adapt GPIO info here.
43  * @note   GPIO_CHANNEL_X_GROUP_NUM:           GPIO group number of channel X.
44  *         GPIO_CHANNEL_X_GROUP_Y_PIN_NUM:     GPIO pin number in channel X group Y.
45  *         GPIO_CHANNEL_X_GROUP_Y_CB_START_ID: GPIO callback start ID in channel X group Y. The callback functions
46  *                                             of all GPIO pins are registered in the same array. The array length
47  *                                             is equal to the number of all GPIO pins. The value starts from 0 and
48  *                                             is accumulated based on the number of pins in each group.
49  *         GPIO_CHANNEL_X_PIN_NUM:             GPIO number of channel X.
50  *
51  *         GPIO_PIN_NUM:                       GPIO sum number of all channel.
52  */
53 #define GPIO_CHANNEL_0_GROUP_NUM            1
54 #define GPIO_CHANNEL_0_GROUP_0_PIN_NUM      8
55 #define GPIO_CHANNEL_0_GROUP_0_CB_START_ID  0
56 #define GPIO_CHANNEL_0_PIN_NUM              (GPIO_CHANNEL_0_GROUP_0_PIN_NUM)
57 
58 #define GPIO_CHANNEL_1_GROUP_NUM            1
59 #define GPIO_CHANNEL_1_GROUP_0_PIN_NUM      8
60 #define GPIO_CHANNEL_1_GROUP_0_CB_START_ID  (GPIO_CHANNEL_0_GROUP_0_CB_START_ID + GPIO_CHANNEL_0_PIN_NUM)
61 #define GPIO_CHANNEL_1_PIN_NUM              (GPIO_CHANNEL_1_GROUP_0_PIN_NUM)
62 
63 #define GPIO_CHANNEL_2_GROUP_NUM            1
64 #define GPIO_CHANNEL_2_GROUP_0_PIN_NUM      3
65 #define GPIO_CHANNEL_2_GROUP_0_CB_START_ID  (GPIO_CHANNEL_1_GROUP_0_CB_START_ID + GPIO_CHANNEL_1_PIN_NUM)
66 #define GPIO_CHANNEL_2_PIN_NUM              (GPIO_CHANNEL_2_GROUP_0_PIN_NUM)
67 
68 #define GPIO_PIN_NUM (GPIO_CHANNEL_0_PIN_NUM + GPIO_CHANNEL_1_PIN_NUM + GPIO_CHANNEL_2_PIN_NUM)
69 
70 #define GPIO_CHANNELS_NUM GPIO_CHANNEL_MAX_NUM
71 
72 /**
73  * @brief  Definition of GPIO Channel index.
74  * @note   GPIO Channels number might be different for each chip and core.
75  */
76 typedef enum gpio_channel {
77     GPIO_CHANNEL_0 = 0,         /*!< GPIO Channel 0 */
78     GPIO_CHANNEL_1,             /*!< GPIO Channel 1 */
79     GPIO_CHANNEL_2,             /*!< GPIO Channel 2 */
80     GPIO_CHANNEL_MAX_NUM
81 } gpio_channel_t;
82 
83 /**
84  * @brief  Get GPIO channel info.
85  * @param  [in]  channel The channel id of GPIO.
86  * @return GPIO group info of target channel. See @ref hal_gpio_channel_info_t
87  */
88 hal_gpio_channel_info_t *gpio_porting_channel_info_get(uint32_t channel);
89 
90 /**
91  * @brief  Get GPIO group context of target channel and group.
92  * @param  [in]  channel The channel id of GPIO.
93  * @param  [in]  group The group id of GPIO.
94  * @return GPIO group context of target channel and group. See @ref hal_gpio_group_context_t
95  */
96 hal_gpio_group_context_t *gpio_porting_group_context_get(uint32_t channel, uint32_t group);
97 
98 /**
99  * @brief  Clean all GPIO context of target channel.
100  * @param  [in]  channel The channel id of GPIO.
101  * @param  [in]  group_num Group number of GPIO channel.
102  */
103 void gpio_porting_channel_context_clean(uint32_t channel, uint32_t group_num);
104 
105 /**
106  * @brief  Get GPIO base addr of of target channel.
107  * @param  [in]  channel The channel id of gpio.
108  * @return GPIO base addr of of target channel.
109  */
110 uintptr_t gpio_porting_base_addr_get(uint32_t channel);
111 
112 /**
113  * @brief  Enable ulp gpio interrupt, set ulp gpio clk as 32K.
114  * @param  on True enable and set clk as 32K, false disable ulp gpio interrupt.
115  */
116 void gpio_ulp_int_en(bool on);
117 
118 void gpio_select_core(pin_t pin, cores_t core);
119 
120 /**
121  * @}
122  */
123 
124 #ifdef __cplusplus
125 #if __cplusplus
126 }
127 #endif /* __cplusplus */
128 #endif /* __cplusplus */
129 
130 #endif