core_gpio.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #ifndef __CORE_GPIO_H__
  22. #define __CORE_GPIO_H__
  23. #include "bsp_common.h"
  24. /**
  25. * @brief GPIO全局初始化
  26. *
  27. * @param Fun 中断回调函数,回调时,PIN序号是pData,void *->uint32_t
  28. */
  29. void GPIO_GlobalInit(CBFuncEx_t Fun);
  30. /**
  31. * @brief GPIO初始化
  32. *
  33. * @param Pin Pin序号
  34. * @param IsInput 是否为输入功能,1是,0否
  35. * @param InitValue 初始电平,1高,0低,只对输出有效
  36. */
  37. void GPIO_Config(uint32_t Pin, uint8_t IsInput, uint8_t InitValue);
  38. /**
  39. * @brief GPIO上下拉控制
  40. *
  41. * @param Pin Pin序号
  42. * @param IsPull 是否需要上下拉
  43. * @param IsUp 是否上拉
  44. */
  45. void GPIO_PullConfig(uint32_t Pin, uint8_t IsPull, uint8_t IsUp);
  46. /**
  47. * @brief GPIO外部中断初始化
  48. *
  49. * @param Pin Pin序号
  50. * @param IsLevel 是否是电平中断,0边沿型,1电平型
  51. * @param IsRiseHigh 上升沿或者高电平
  52. * @param IsFallLow 下降沿或者低电平
  53. */
  54. void GPIO_ExtiConfig(uint32_t Pin, uint8_t IsLevel, uint8_t IsRiseHigh, uint8_t IsFallLow);
  55. /**
  56. * @brief GPIO复用功能
  57. *
  58. * @param Pin Pin序号
  59. * @param Function 复用功能,这个需要根据芯片实际情况决定,当前是0~3,注意GPIO功能是1
  60. */
  61. void GPIO_Iomux(uint32_t Pin, uint32_t Function);
  62. /**
  63. * @brief GPIO输出电平
  64. *
  65. * @param Pin Pin序号
  66. * @param Level 1高电平,0低电平
  67. */
  68. void GPIO_Output(uint32_t Pin, uint8_t Level);
  69. /**
  70. * @brief 读取GPIO输入电平
  71. *
  72. * @param Pin Pin序号
  73. * @return 1高电平, 0低电平,其他无效
  74. */
  75. uint8_t GPIO_Input(uint32_t Pin);
  76. /**
  77. * @brief GPIO同一端口多个pin输出电平,针对类似STM32GPIO分布有效
  78. *
  79. * @param Port 端口号
  80. * @param Pins Pin序号组合
  81. * @param Level 1高电平,0低电平
  82. */
  83. void GPIO_OutputMulti(uint32_t Port, uint32_t Pins, uint32_t Level);
  84. /**
  85. * @brief 读取GPIO同一端口多个pin输入电平
  86. *
  87. * @param Port 端口号
  88. * @return
  89. */
  90. uint32_t GPIO_InputMulti(uint32_t Port);
  91. void GPIO_ExtiSetCB(uint32_t Pin, CBFuncEx_t CB, void *pParam);
  92. void GPIO_ODConfig(uint32_t Pin, uint8_t InitValue);
  93. #endif