• 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 HAL pinctrl \n
16  *
17  * History: \n
18  * 2022-08-25, Create file. \n
19  */
20 #ifndef HAL_PINCTRL_H
21 #define HAL_PINCTRL_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 #include "pinctrl_porting.h"
26 
27 #ifdef __cplusplus
28 #if __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 #endif /* __cplusplus */
32 
33 /**
34  * @defgroup drivers_hal_pinctrl_api Pinctrl
35  * @ingroup  drivers_hal_pinctrl
36  * @{
37  */
38 
39 /**
40  * @if Eng
41  * @brief  Set mode for hal pin.
42  * @param  [in] pin Definition of IO. see @ref pin_t
43  * @param  [in] mode Multiplexing mode. see @ref pin_mode_t
44  * @retval ERRCODE_SUCC Success.
45  * @retval Other        Failure. For details, see @ref errcode_t
46  * @else
47  * @brief  HAL层pin设置复用模式。
48  * @param  [in] pin io, 参考 @ref pin_t
49  * @param  [in] mode 复用模式。参考 @ref pin_mode_t
50  * @retval ERRCODE_SUCC 成功
51  * @retval Other        失败。参考 @ref errcode_t
52  * @endif
53  */
54 typedef errcode_t (*hal_pin_set_mode)(pin_t pin, pin_mode_t mode);
55 
56 /**
57  * @if Eng
58  * @brief  Get mode for hal pin.
59  * @param  [in] pin Definition of IO. see @ref pin_t
60  * @return Multiplexing mode. see @ref pin_mode_t
61  * @else
62  * @brief  HAL层pin获取复用模式。
63  * @param  [in] pin io, 参考 @ref pin_t
64  * @return 复用模式。参考 @ref pin_mode_t
65  * @endif
66  */
67 typedef pin_mode_t (*hal_pin_get_mode)(pin_t pin);
68 
69 /**
70  * @if Eng
71  * @brief  Set drive-strength for hal pin.
72  * @param  [in] pin Definition of IO. see @ref pin_t
73  * @param  [in] ds Drive strength. see @ref pin_drive_strength_t
74  * @retval ERRCODE_SUCC Success.
75  * @retval Other        Failure. For details, see @ref errcode_t
76  * @else
77  * @brief  HAL层pin设置驱动能力。
78  * @param  [in] pin io. 参考 @ref pin_t
79  * @param  [in] ds 驱动能力。参考 @ref pin_drive_strength_t
80  * @retval ERRCODE_SUCC 成功
81  * @retval Other        失败。参考 @ref errcode_t
82  * @endif
83  */
84 typedef errcode_t (*hal_pin_set_ds)(pin_t pin, pin_drive_strength_t ds);
85 
86 /**
87  * @if Eng
88  * @brief  Get drive-strength for hal pin.
89  * @param  [in] pin Definition of IO. see @ref pin_t
90  * @return Drive strength. see @ref pin_drive_strength_t
91  * @else
92  * @brief  HAL层pin获取驱动能力。
93  * @param  [in] pin io. 参考 @ref pin_t
94  * @return 驱动能力。参考 @ref pin_drive_strength_t
95  * @endif
96  */
97 typedef pin_drive_strength_t (*hal_pin_get_ds)(pin_t pin);
98 
99 /**
100  * @if Eng
101  * @brief  Set pull-up/down for hal pin.
102  * @param  [in] pin Definition of IO. see @ref pin_t
103  * @param  [in] pull_type pull-up/down type. see @ref pin_pull_t
104  * @retval ERRCODE_SUCC Success.
105  * @retval Other        Failure. For details, see @ref errcode_t
106  * @else
107  * @brief  HAL层pin设置上下拉。
108  * @param  [in] pin io, 参考 @ref pin_t
109  * @param  [in] pull_type 上下拉类型。参考 @ref pin_pull_t
110  * @retval ERRCODE_SUCC 成功
111  * @retval Other        失败。参考 @ref errcode_t
112  * @endif
113  */
114 typedef errcode_t (*hal_pin_set_pull)(pin_t pin, pin_pull_t pull_type);
115 
116 /**
117  * @if Eng
118  * @brief  Get pull-up/down status for hal pin.
119  * @param  [in] pin Definition of IO. see @ref pin_t
120  * @return pull-up/down status. see @ref pin_pull_t
121  * @else
122  * @brief  HAL层pin获取上下拉状态。
123  * @param  [in] pin io, 参考 @ref pin_t
124  * @return 上下拉状态。参考 @ref pin_pull_t
125  * @endif
126  */
127 typedef pin_pull_t (*hal_pin_get_pull)(pin_t pin);
128 
129 #if defined(CONFIG_PINCTRL_SUPPORT_IE)
130 /**
131  * @if Eng
132  * @brief  Set INPUT-Enabled status for hal pin.
133  * @param  [in] pin Definition of IO. see @ref pin_t
134  * @param  [in] ie INPUT-Enabled status. see @ref pin_input_enable_t
135  * @retval ERRCODE_SUCC Success.
136  * @retval Other        Failure. For details, see @ref errcode_t
137  * @else
138  * @brief  HAL层pin设置输入使能状态。
139  * @param  [in] pin io, 参考 @ref pin_t
140  * @param  [in] ie 输入使能状态。参考 @ref pin_input_enable_t
141  * @retval ERRCODE_SUCC 成功
142  * @retval Other        失败。参考 @ref errcode_t
143  * @endif
144  */
145 typedef errcode_t (*hal_pin_set_ie)(pin_t pin, pin_input_enable_t ie);
146 
147 /**
148  * @if Eng
149  * @brief  Get INPUT-Enabled status for hal pin.
150  * @param  [in] pin Definition of IO. see @ref pin_t
151  * @return INPUT-Enabled status. see @ref pin_input_enable_t
152  * @else
153  * @brief  HAL层pin获取输入使能状态。
154  * @param  [in] pin io, 参考 @ref pin_t
155  * @return 输入使能状态。参考 @ref pin_input_enable_t
156  * @endif
157  */
158 typedef pin_input_enable_t (*hal_pin_get_ie)(pin_t pin);
159 #endif /* CONFIG_PINCTRL_SUPPORT_IE */
160 
161 #if defined(CONFIG_PINCTRL_SUPPORT_ST)
162 /**
163  * @if Eng
164  * @brief  Set schmitt-trigger status for hal pin.
165  * @param  [in] pin Definition of IO. see @ref pin_t
166  * @param  [in] st Schmitt-trigger status. see @ref pin_schmitt_trigger_t
167  * @retval ERRCODE_SUCC Success.
168  * @retval Other        Failure. For details, see @ref errcode_t
169  * @else
170  * @brief  HAL层pin设置施密特触发状态。
171  * @param  [in] pin io, 参考 @ref pin_t
172  * @param  [in] st 施密特触发状态。参考 @ref pin_schmitt_trigger_t
173  * @retval ERRCODE_SUCC 成功
174  * @retval Other        失败。参考 @ref errcode_t
175  * @endif
176  */
177 typedef errcode_t (*hal_pin_set_st)(pin_t pin, pin_schmitt_trigger_t st);
178 
179 /**
180  * @if Eng
181  * @brief  Get schmitt-trigger status for hal pin.
182  * @param  [in] pin Definition of IO. see @ref pin_t
183  * @return Schmitt-trigger status. see @ref pin_schmitt_trigger_t
184  * @else
185  * @brief  HAL层pin获取施密特触发状态。
186  * @param  [in] pin io, 参考 @ref pin_t
187  * @return 施密特触发状态。参考 @ref pin_schmitt_trigger_t
188  * @endif
189  */
190 typedef pin_schmitt_trigger_t (*hal_pin_get_st)(pin_t pin);
191 #endif /* CONFIG_PINCTRL_SUPPORT_ST */
192 
193 
194 typedef struct {
195     hal_pin_set_mode set_mode;      /*!< @if Eng Set multiplexing mode interface.
196                                          @else   设置复用模式接口。 @endif */
197     hal_pin_get_mode get_mode;      /*!< @if Eng Get mode interface.
198                                          @else   获取复用模式接口 @endif */
199     hal_pin_set_ds   set_ds;        /*!< @if Eng Set drive strength interface.
200                                          @else   设置驱动能力接口。 @endif */
201     hal_pin_get_ds   get_ds;        /*!< @if Eng Get drive strength interface.
202                                          @else   获取驱动能力接口。 @endif */
203     hal_pin_set_pull set_pull;      /*!< @if Eng Set pull-up/down interface.
204                                          @else   获取上下拉接口。 @endif */
205     hal_pin_get_pull get_pull;      /*!< @if Eng Get pull-up/down interface.
206                                          @else   获取上下拉接口。 @endif */
207 #if defined(CONFIG_PINCTRL_SUPPORT_IE)
208     hal_pin_set_ie   set_ie;        /*!< @if Eng Set input enable interface.
209                                          @else   设置输入使能接口。 @endif */
210     hal_pin_get_ie   get_ie;        /*!< @if Eng Get input enable interface.
211                                          @else   获取输入使能接口。 @endif */
212 #endif /* CONFIG_PINCTRL_SUPPORT_IE */
213 #if defined(CONFIG_PINCTRL_SUPPORT_ST)
214     hal_pin_set_st   set_st;        /*!< @if Eng Set schmitt trigger interface.
215                                          @else   设置施密特触发接口。 @endif */
216     hal_pin_get_st   get_st;        /*!< @if Eng Get schmitt trigger interface.
217                                          @else   获取施密特触发接口。 @endif */
218 #endif /* CONFIG_PINCTRL_SUPPORT_ST */
219 } hal_pin_funcs_t;
220 
221 /**
222  * @if Eng
223  * @brief  Register @ref hal_pin_funcs_t into the g_hal_pins_funcs.
224  * @param  [in]  funcs Interface between pin driver and pin hal.
225  * @retval ERRCODE_SUCC Success.
226  * @retval Other        Failure. For details, see @ref errcode_t
227  * @else
228  * @brief  注册 @ref hal_pin_funcs_t 到 g_hal_pins_funcs
229  * @param  [in]  funcs Driver层pin和HAL层pin的接口实例。
230  * @retval ERRCODE_SUCC 成功
231  * @retval Other        失败,参考 @ref errcode_t
232  * @endif
233  */
234 errcode_t hal_pin_register_funcs(hal_pin_funcs_t *funcs);
235 
236 /**
237  * @if Eng
238  * @brief  Unregister @ref hal_pin_funcs_t from the g_hal_pins_funcs.
239  * @return ERRCODE_SUCC Success.
240  * @retval Other        Failure. For details, see @ref errcode_t
241  * @else
242  * @brief  g_hal_pins_funcs @ref hal_pin_funcs_t
243  * @return ERRCODE_SUCC 成功
244  * @retval Other        失败,参考 @ref errcode_t
245  * @endif
246  */
247 errcode_t hal_pin_unregister_funcs(void);
248 
249 /**
250  * @if Eng
251  * @brief  Get interface between pin driver and pin hal, see @ref hal_pin_funcs_t
252  * @return Interface between pin driver and pin hal, see @ref hal_pin_funcs_t
253  * @else
254  * @brief  获取Driver层pin和HAL层pin的接口实例,参考 @ref hal_pin_funcs_t
255  * @return Driver层pin和HAL层pin的接口实例,参考 @ref hal_pin_funcs_t
256  * @endif
257  */
258 hal_pin_funcs_t *hal_pin_get_funcs(void);
259 
260 /**
261  * @}
262  */
263 
264 #ifdef __cplusplus
265 #if __cplusplus
266 }
267 #endif /* __cplusplus */
268 #endif /* __cplusplus */
269 
270 #endif
271