1 /* 2 * Copyright (c) 2022 OpenLuat & AirM2M 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 * this software and associated documentation files (the "Software"), to deal in 6 * the Software without restriction, including without limitation the rights to 7 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 * the Software, and to permit persons to whom the Software is furnished to do so, 9 * subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in all 12 * copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 */ 21 22 #ifndef __CORE_GPIO_H__ 23 #define __CORE_GPIO_H__ 24 #include "bsp_common.h" 25 /** 26 * @brief GPIO全局初始化 27 * 28 * @param Fun 中断回调函数,回调时,PIN序号是pData,void *->uint32_t 29 30 */ 31 void GPIO_GlobalInit(CBFuncEx_t Fun); 32 33 /** 34 * @brief GPIO初始化 35 * 36 * @param Pin Pin序号 37 * @param IsInput 是否为输入功能,1是,0否 38 * @param InitValue 初始电平,1高,0低,只对输出有效 39 40 */ 41 void GPIO_Config(uint32_t Pin, uint8_t IsInput, uint8_t InitValue); 42 /** 43 * @brief GPIO上下拉控制 44 * 45 * @param Pin Pin序号 46 * @param IsPull 是否需要上下拉 47 * @param IsUp 是否上拉 48 49 */ 50 void GPIO_PullConfig(uint32_t Pin, uint8_t IsPull, uint8_t IsUp); 51 52 /** 53 * @brief GPIO外部中断初始化 54 * 55 * @param Pin Pin序号 56 * @param IsLevel 是否是电平中断,0边沿型,1电平型 57 * @param IsRiseHigh 上升沿或者高电平 58 * @param IsFallLow 下降沿或者低电平 59 */ 60 void GPIO_ExtiConfig(uint32_t Pin, uint8_t IsLevel, uint8_t IsRiseHigh, uint8_t IsFallLow); 61 62 /** 63 * @brief GPIO复用功能 64 * 65 * @param Pin Pin序号 66 * @param Function 复用功能,这个需要根据芯片实际情况决定,当前是0~3,注意GPIO功能是1 67 */ 68 void GPIO_Iomux(uint32_t Pin, uint32_t Function); 69 70 /** 71 * @brief GPIO输出电平 72 * 73 * @param Pin Pin序号 74 * @param Level 1高电平,0低电平 75 */ 76 void GPIO_Output(uint32_t Pin, uint8_t Level); 77 78 /** 79 * @brief 读取GPIO输入电平 80 * 81 * @param Pin Pin序号 82 * @return 1高电平, 0低电平,其他无效 83 */ 84 uint8_t GPIO_Input(uint32_t Pin); 85 86 /** 87 * @brief GPIO同一端口多个pin输出电平,针对类似STM32GPIO分布有效 88 * 89 * @param Port 端口号 90 * @param Pins Pin序号组合 91 * @param Level 1高电平,0低电平 92 */ 93 void GPIO_OutputMulti(uint32_t Port, uint32_t Pins, uint32_t Level); 94 95 /** 96 * @brief 读取GPIO同一端口多个pin输入电平 97 * 98 * @param Port 端口号 99 * @return 100 */ 101 uint32_t GPIO_InputMulti(uint32_t Port); 102 103 void GPIO_ExtiSetHWTimerCB(CBFuncEx_t CB, void *pParam); 104 void GPIO_ODConfig(uint32_t Pin, uint8_t InitValue); 105 #endif 106