1 /** 2 * @file hi_gpio.h 3 * 4 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /** 19 * @defgroup iot_gpio GPIO 20 * @ingroup drivers 21 */ 22 #ifndef __HI_GPIO_H__ 23 #define __HI_GPIO_H__ 24 25 26 #include <hi_types_base.h> 27 28 /** 29 * @ingroup iot_gpio 30 * 31 * GPIO ID. 32 */ 33 typedef enum { 34 HI_GPIO_IDX_0, /**< GPIO0*/ 35 HI_GPIO_IDX_1, /**< GPIO1*/ 36 HI_GPIO_IDX_2, /**< GPIO2*/ 37 HI_GPIO_IDX_3, /**< GPIO3*/ 38 HI_GPIO_IDX_4, /**< GPIO4*/ 39 HI_GPIO_IDX_5, /**< GPIO5*/ 40 HI_GPIO_IDX_6, /**< GPIO6*/ 41 HI_GPIO_IDX_7, /**< GPIO7*/ 42 HI_GPIO_IDX_8, /**< GPIO8*/ 43 HI_GPIO_IDX_9, /**< GPIO9*/ 44 HI_GPIO_IDX_10, /**< GPIO10*/ 45 HI_GPIO_IDX_11, /**< GPIO11*/ 46 HI_GPIO_IDX_12, /**< GPIO12*/ 47 HI_GPIO_IDX_13, /**< GPIO13*/ 48 HI_GPIO_IDX_14, /**< GPIO14*/ 49 HI_GPIO_IDX_MAX, /**< Maximum value, which cannot be used.CNcomment:最大值,不可输入使用CNend*/ 50 } hi_gpio_idx; 51 52 53 /** 54 * @ingroup iot_gpio 55 * 56 * I/O level. CNcomment:GPIO电平状态。CNend 57 */ 58 typedef enum { 59 HI_GPIO_VALUE0 = 0, /**< Low level.CNcomment:低电平CNend*/ 60 HI_GPIO_VALUE1 /**< High level.CNcomment:高电平CNend*/ 61 } hi_gpio_value; 62 63 /** 64 * @ingroup iot_gpio 65 * 66 * I/O direction. CNcomment:GPIO方向。CNend 67 */ 68 typedef enum { 69 HI_GPIO_DIR_IN = 0, /**< Input.CNcomment:输入方向CNend*/ 70 HI_GPIO_DIR_OUT /**< Output.CNcomment:输出方向CNend*/ 71 } hi_gpio_dir; 72 73 /** 74 * @ingroup iot_gpio 75 * 76 * I/O interrupt trigger mode. This bit is used with HI_GPIO_INT_POLARITY. 77 CNcomment:GPIO中断触发方式,与hi_gpio_int_polarity配合使用。CNend 78 */ 79 typedef enum { 80 HI_INT_TYPE_LEVEL = 0, /**< The interrupt is triggered in level-sensitive mode. CNcomment:电平触发中断CNend */ 81 HI_INT_TYPE_EDGE /**< Interrupt triggered at the rising edge or falling edge.CNcomment:边沿触发中断CNend */ 82 } hi_gpio_int_type; 83 84 /** 85 * @ingroup iot_gpio 86 * 87 * I/O interrupt polarity. This pin is used with HI_GPIO_INT. 88 CNcomment:IO中断极性,与hi_gpio_int_type配合使用。CNend 89 */ 90 typedef enum { 91 HI_GPIO_EDGE_FALL_LEVEL_LOW = 0, /**< Interrupt triggered at low level or falling edge. 92 CNcomment:低电平或下降沿触发中断CNend */ 93 HI_GPIO_EDGE_RISE_LEVEL_HIGH /**< Interrupt triggered at high level or rising edge. 94 CNcomment:高电平或上升沿触发中断CNend */ 95 } hi_gpio_int_polarity; 96 97 98 /** 99 * @ingroup iot_gpio 100 * @brief Callback function when GPIO interruption happens.CNcomment:GPIO中断回调函数。CNend 101 * 102 * @par 描述: 103 * Callback function when GPIO interruption happens.CNcomment:GPIO中断回调函数。CNend 104 * 105 * @attention None 106 * 107 * @param arg [IN] type #hi_void *,arg of interrupt callback function. CNcomment:中断回调函数入参。CNend 108 * 109 * @retval None 110 * @par 依赖: 111 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 112 * @see None 113 */ 114 typedef hi_void (*gpio_isr_callback) (hi_void *arg); 115 116 /** 117 * @ingroup iot_gpio 118 * @brief Initializes GPIO module.CNcomment:GPIO模块初始化。CNend 119 * 120 * @par 描述: 121 * Initializes GPIO module.CNcomment:GPIO模块初始化。CNend 122 * 123 * @attention 124 * @li This API needs to be invoked during initialization to enable the GPIO interrupt so that the I/O interrupt 125 * can be responded.CNcomment:需要在初始化阶段调用该接口使能GPIO中断,使得IO中断可以得到响应。CNend 126 * @li This interface cannot be invoked repeatedly. It can be invoked only once in the initialization phase. 127 CNcomment:该接口不支持重复调用,只能在初始化阶段调用一次。CNend 128 * 129 * @param None 130 * 131 * @retval #0 Success. 132 * @retval #Other Failure. For details, see hi_errno.h. 133 * @par 依赖: 134 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 135 * @see None 136 */ 137 hi_u32 hi_gpio_init(hi_void); 138 139 /** 140 * @ingroup iot_gpio 141 * @brief Deinitializes GPIO module. CNcomment:GPIO模块去初始化。CNend 142 * 143 * @par 描述: 144 * Deinitializes GPIO module. CNcomment:GPIO模块去初始化。CNend 145 * 146 * @attention 147 * @li This interface is used to disable the GPIO interrupt. After the GPIO interrupt is called, the GPIO interrupt 148 * cannot be responded.CNcomment:该接口功能为去使能GPIO中断,调用后GPIO中断将得不到响应。CNend 149 * 150 * @param None 151 * 152 * @retval #0 Success. 153 * @retval #Other Failure. For details, see hi_errno.h. 154 * @par 依赖: 155 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 156 * @see None 157 */ 158 hi_u32 hi_gpio_deinit(hi_void); 159 160 /** 161 * @ingroup iot_gpio 162 * @brief Sets the direction of a single I/O pin.CNcomment:设置某个GPIO管脚方向。CNend 163 * 164 * @par 描述: 165 * Sets the direction of a single I/O pin.CNcomment:设置某个GPIO管脚方向。CNend 166 * 167 * @attention None 168 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 169 * @param dir [IN] type #hi_gpio_dir,I/O direction.CNcomment:GPIO方向。CNend 170 * 171 * @retval #0 Success. 172 * @retval #Other Failure. For details, see hi_errno.h. 173 * @par 依赖: 174 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 175 * @see hi_gpio_get_dir 176 */ 177 hi_u32 hi_gpio_set_dir(hi_gpio_idx id, hi_gpio_dir dir); 178 179 /** 180 * @ingroup iot_gpio 181 * @brief Gets the direction of a single I/O pin.CNcomment:获取某个GPIO管脚方向。CNend 182 * 183 * @par 描述: 184 * Gets the direction of a single I/O pin.CNcomment:获取某个GPIO管脚方向。CNend 185 * 186 * @attention None 187 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 188 * @param dir [OUT] type #hi_gpio_dir*,I/O direction.CNcomment:GPIO方向。CNend 189 * 190 * @retval #0 Success. 191 * @retval #Other Failure. For details, see hi_errno.h. 192 * @par 依赖: 193 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 194 * @see hi_gpio_set_dir 195 */ 196 hi_u32 hi_gpio_get_dir(hi_gpio_idx id, hi_gpio_dir *dir); 197 198 /** 199 * @ingroup iot_gpio 200 * @brief Sets the output level of a single I/O pin.CNcomment:设置单个GPIO管脚输出电平状态。CNend 201 * 202 * @par 描述: 203 * Sets the output level of a single I/O pin.CNcomment:设置单个GPIO管脚输出电平状态。CNend 204 * 205 * @attention None 206 * 207 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 208 * @param val [IN] type #hi_gpio_value,output value. CNcomment:输出值。CNend 209 * @li 0:low level.CNcomment:低电平。CNend 210 * @li 1:high level.CNcomment:高电平。CNend 211 * 212 * @retval #0 Success. 213 * @retval #Other Failure. For details, see hi_errno.h. 214 * @par 依赖: 215 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 216 * @see hi_gpio_get_input_val。 217 */ 218 hi_u32 hi_gpio_set_ouput_val(hi_gpio_idx id, hi_gpio_value val); 219 220 /** 221 * @ingroup iot_gpio 222 * @brief Obtains the output level of a single I/O pin.CNcomment:获取某个IO管脚输出电平状态。CNend 223 * 224 * @par 描述: 225 * Obtains the output level of a single I/O pin.CNcomment:获取某个IO管脚输出电平状态。CNend 226 * 227 * @attention None 228 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 229 * @param val [OUT] type #hi_gpio_value*,Output value.CNcomment:输出值。CNend 230 * @li 0:low level.CNcomment:低电平。CNend 231 * @li 1:high level.CNcomment:高电平。CNend 232 * 233 * @retval #0 Success. 234 * @retval #Other Failure. For details, see hi_errno.h. 235 * @par 依赖: 236 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 237 * @see hi_gpio_set_ouput_val。 238 */ 239 hi_u32 hi_gpio_get_output_val(hi_gpio_idx id, hi_gpio_value* val); 240 241 /** 242 * @ingroup iot_gpio 243 * @brief Obtains the input level of a single I/O pin.CNcomment:获取某个IO管脚输入电平状态。CNend 244 * 245 * @par 描述: 246 * Obtains the input level of a single I/O pin.CNcomment:获取某个IO管脚输入电平状态。CNend 247 * 248 * @attention None 249 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 250 * @param val [OUT] type #hi_gpio_value*,Output value.CNcomment:输出值。CNend 251 * @li 0:low level.CNcomment:低电平。CNend 252 * @li 1:high level.CNcomment:高电平。CNend 253 * 254 * @retval #0 Success. 255 * @retval #Other Failure. For details, see hi_errno.h. 256 * @par 依赖: 257 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 258 * @see None 259 */ 260 hi_u32 hi_gpio_get_input_val(hi_gpio_idx id, hi_gpio_value *val); 261 262 /** 263 * @ingroup iot_gpio 264 * @brief Enable GPIO interruption.CNcomment:使能某个GPIO的中断功能。CNend 265 * 266 * @par 描述: 267 * Enable GPIO interruption.CNcomment:使能某个GPIO的中断功能。CNend 268 * 269 * @attention None 270 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 271 * @param int_type [IN] type #hi_gpio_int_type,Interruption type.CNcomment:中断类型。CNend 272 * @param int_polarity [IN] type #hi_gpio_int_polarity,Interruption polarity.CNcomment:中断极性。CNend 273 * @param func [IN] type #gpio_isr_callback_func,Callback function of interruption. 274 CNcomment:中断回调函数。CNend 275 * @param arg [IN] type #hi_void *,arg of interrupt callback function. CNcomment:中断回调函数入参。CNend 276 * 277 * @retval #0 Success. 278 * @retval #Other Failure. For details, see hi_errno.h. 279 * @par 依赖: 280 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 281 * @see hi_gpio_unregister_isr_function。 282 */ 283 hi_u32 hi_gpio_register_isr_function(hi_gpio_idx id, hi_gpio_int_type int_type, hi_gpio_int_polarity int_polarity, 284 gpio_isr_callback func, hi_void *arg); 285 286 /** 287 * @ingroup iot_gpio 288 * @brief Disable GPIO interruption.CNcomment:去使能某个GPIO的中断功能。CNend 289 * 290 * @par 描述: 291 * Disable GPIO interruption.CNcomment:去使能某个GPIO的中断功能。CNend 292 * 293 * @attention None 294 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 295 * 296 * @retval #0 Success. 297 * @retval #Other Failure. For details, see hi_errno.h. 298 * @par 依赖: 299 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 300 * @see hi_gpio_register_isr_function。 301 */ 302 hi_u32 hi_gpio_unregister_isr_function(hi_gpio_idx id); 303 304 /** 305 * @ingroup iot_gpio 306 * @brief Mask GPIO interruption.CNcomment:屏蔽某个GPIO的中断功能。CNend 307 * 308 * @par 描述: 309 * Mask GPIO interruption.CNcomment:屏蔽某个GPIO的中断功能。CNend 310 * 311 * @attention If this interface is called before hi_gpio_register_isr_function, the hi_gpio_register_isr_function 312 * interface will unmask the GPIO interruption. 313 * CNcomment:若此接口在hi_gpio_register_isr_function之前调用,hi_gpio_register_isr_function会将配置 314 * 修改为不屏蔽GPIO中断。CNend 315 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 316 * @param is_mask [IN] type #hi_bool,Interruption type.CNcomment:中断类型。CNend 317 * @li HI_FALSE:Unmask I/O interruption.CNcomment:不屏蔽GPIO中断。CNend 318 * @li HI_TRUE: Mask I/O interruption.CNcomment:屏蔽GPIO中断。CNend 319 * 320 * @retval #0 Success. 321 * @retval #Other Failure. For details, see hi_errno.h. 322 * @par 依赖: 323 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 324 * @see None 325 */ 326 hi_u32 hi_gpio_set_isr_mask(hi_gpio_idx id, hi_bool is_mask); 327 328 /** 329 * @ingroup iot_gpio 330 * @brief Set GPIO interruption type and polarity.CNcomment:设置某个GPIO的中断触发方式。CNend 331 * 332 * @par 描述: 333 * Set GPIO interruption type and polarity.CNcomment:设置某个GPIO的中断触发方式。CNend 334 * 335 * @attention If this interface is called before hi_gpio_register_isr_function, hi_gpio_register_isr_function 336 * will overwrite the configurations. 337 * CNcomment:若此接口在hi_gpio_register_isr_function之前调用,hi_gpio_register_isr_function会覆盖 338 * 本接口的配置。CNend 339 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 340 * @param int_type [IN] type #hi_gpio_int_type,Interruption type.CNcomment:中断类型。CNend 341 * @param int_polarity [IN] type #hi_gpio_int_polarity,Interruption polarity.CNcomment:中断极性。CNend 342 * 343 * @retval #0 Success. 344 * @retval #Other Failure. For details, see hi_errno.h. 345 * @par 依赖: 346 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 347 * @see None 348 */ 349 hi_u32 hi_gpio_set_isr_mode(hi_gpio_idx id, hi_gpio_int_type int_type, hi_gpio_int_polarity int_polarity); 350 351 #endif 352