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 16 #ifndef __BSP_GPIO_H__ 17 #define __BSP_GPIO_H__ 18 #include<hi_boot_rom.h> 19 #define hi_io_val_set(cond, id, reg_val) \ 20 if (cond) \ 21 { \ 22 (reg_val) |= (hi_u16)(1 << (id)); \ 23 } \ 24 else \ 25 { \ 26 (reg_val) &= ~(hi_u16)(1 << (id)); \ 27 } 28 29 #define hi_io_dir_get(cond, id, val_addr) \ 30 if ((cond) & (hi_u16)(1 << (id))) \ 31 { \ 32 *(val_addr) = HI_GPIO_DIR_OUT; \ 33 } \ 34 else \ 35 { \ 36 *(val_addr) = HI_GPIO_DIR_IN; \ 37 } 38 39 #define hi_io_val_get(cond, id, val_addr) \ 40 if ((cond) & (hi_u16)(1 << (id))) \ 41 { \ 42 *(val_addr) = HI_GPIO_VALUE1; \ 43 } \ 44 else \ 45 { \ 46 *(val_addr) = HI_GPIO_VALUE0; \ 47 } 48 49 /** 50 * @ingroup iot_gpio 51 * 52 * I/O level. CNcomment:GPIO电平状态。CNend 53 */ 54 typedef enum { 55 HI_GPIO_VALUE0 = 0, /**< Low level.CNcomment:低电平CNend*/ 56 HI_GPIO_VALUE1 /**< High level.CNcomment:高电平CNend*/ 57 } hi_gpio_value; 58 59 /** 60 * @ingroup iot_gpio 61 * 62 * I/O direction. CNcomment:GPIO方向。CNend 63 */ 64 typedef enum { 65 HI_GPIO_DIR_IN = 0, /**< Input.CNcomment:输入方向CNend*/ 66 HI_GPIO_DIR_OUT /**< Output.CNcomment:输出方向CNend*/ 67 } hi_gpio_dir; 68 69 /** 70 * @ingroup iot_gpio 71 * @brief Gets the direction of a single I/O pin.CNcomment:获取某个GPIO管脚方向。CNend 72 * 73 * @par 描述: 74 * Gets the direction of a single I/O pin.CNcomment:获取某个GPIO管脚方向。CNend 75 * 76 * @attention None 77 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 78 * @param dir [OUT] type #hi_gpio_dir*,I/O direction.CNcomment:GPIO方向。CNend 79 * 80 * @retval #0 Success. 81 * @retval #Other Failure. For details, see hi_errno.h. 82 * @par 依赖: 83 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 84 * @see hi_gpio_set_dir 85 */ 86 hi_u32 hi_gpio_get_dir(hi_gpio_idx id, hi_gpio_dir *dir); 87 88 /** 89 * @ingroup iot_gpio 90 * @brief Sets the direction of a single I/O pin.CNcomment:设置某个GPIO管脚方向。CNend 91 * 92 * @par 描述: 93 * Sets the direction of a single I/O pin.CNcomment:设置某个GPIO管脚方向。CNend 94 * 95 * @attention None 96 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 97 * @param dir [IN] type #hi_gpio_dir,I/O direction.CNcomment:GPIO方向。CNend 98 * 99 * @retval #0 Success. 100 * @retval #Other Failure. For details, see hi_errno.h. 101 * @par 依赖: 102 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 103 * @see hi_gpio_get_dir 104 */ 105 hi_u32 hi_gpio_set_dir(hi_gpio_idx id, hi_gpio_dir dir); 106 107 /** 108 * @ingroup iot_gpio 109 * @brief Obtains the input level of a single I/O pin.CNcomment:获取某个IO管脚输入电平状态。CNend 110 * 111 * @par 描述: 112 * Obtains the input level of a single I/O pin.CNcomment:获取某个IO管脚输入电平状态。CNend 113 * 114 * @attention None 115 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 116 * @param val [OUT] type #hi_gpio_value*,Output value.CNcomment:输出值。CNend 117 * @li 0:low level.CNcomment:低电平。CNend 118 * @li 1:high level.CNcomment:高电平。CNend 119 * 120 * @retval #0 Success. 121 * @retval #Other Failure. For details, see hi_errno.h. 122 * @par 依赖: 123 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 124 * @see None 125 */ 126 hi_u32 hi_gpio_get_input_val(hi_gpio_idx id, hi_gpio_value *val); 127 128 /** 129 * @ingroup iot_gpio 130 * @brief Obtains the output level of a single I/O pin.CNcomment:获取某个IO管脚输出电平状态。CNend 131 * 132 * @par 描述: 133 * Obtains the output level of a single I/O pin.CNcomment:获取某个IO管脚输出电平状态。CNend 134 * 135 * @attention None 136 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 137 * @param val [OUT] type #hi_gpio_value*,Output value.CNcomment:输出值。CNend 138 * @li 0:low level.CNcomment:低电平。CNend 139 * @li 1:high level.CNcomment:高电平。CNend 140 * 141 * @retval #0 Success. 142 * @retval #Other Failure. For details, see hi_errno.h. 143 * @par 依赖: 144 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 145 * @see hi_gpio_set_ouput_val。 146 */ 147 hi_u32 hi_gpio_get_output_val(hi_gpio_idx id, hi_gpio_value* val); 148 149 /** 150 * @ingroup iot_gpio 151 * @brief Sets the output level of a single I/O pin.CNcomment:设置单个GPIO管脚输出电平状态。CNend 152 * 153 * @par 描述: 154 * Sets the output level of a single I/O pin.CNcomment:设置单个GPIO管脚输出电平状态。CNend 155 * 156 * @attention None 157 * 158 * @param id [IN] type #hi_gpio_idx,I/O index.CNcomment:GPIO索引。CNend 159 * @param val [IN] type #hi_gpio_value,output value. CNcomment:输出值。CNend 160 * @li 0:low level.CNcomment:低电平。CNend 161 * @li 1:high level.CNcomment:高电平。CNend 162 * 163 * @retval #0 Success. 164 * @retval #Other Failure. For details, see hi_errno.h. 165 * @par 依赖: 166 * @li hi_gpio.h:Describes GPIO APIs.CNcomment:文件用于描述GPIO相关接口。CNend 167 * @see hi_gpio_get_input_val。 168 */ 169 hi_u32 hi_gpio_set_output_val(hi_gpio_idx id, hi_gpio_value val); 170 171 #endif 172