core_gpio.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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复用功能扩展,目前只有106需要
  64. *
  65. * @param Pin Pin序号
  66. * @param Function 复用功能,这个需要根据芯片实际情况决定,当前是0~15,注意GPIO功能是0
  67. * @IsInput 是否是输入功能
  68. */
  69. void GPIO_IomuxEx(uint32_t Pin, uint32_t Function, uint8_t IsInput);
  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. * @brief 读取GPIO输入电平
  79. *
  80. * @param Pin Pin序号
  81. * @return 1高电平, 0低电平,其他无效
  82. */
  83. uint8_t GPIO_Input(uint32_t Pin);
  84. /**
  85. * @brief 翻转GPIO输出电平
  86. *
  87. * @param Pin Pin序号
  88. * @return 无
  89. */
  90. void GPIO_Toggle(uint32_t Pin);
  91. /**
  92. * @brief GPIO同一端口多个pin输出电平,针对类似STM32GPIO分布有效
  93. *
  94. * @param Port 端口号
  95. * @param Pins Pin序号组合
  96. * @param Level 1高电平,0低电平
  97. */
  98. void GPIO_OutputMulti(uint32_t Port, uint32_t Pins, uint32_t Level);
  99. /**
  100. * @brief 读取GPIO同一端口多个pin输入电平
  101. *
  102. * @param Port 端口号
  103. * @return
  104. */
  105. uint32_t GPIO_InputMulti(uint32_t Port);
  106. /**
  107. * @brief 翻转GPIO同一端口多个pin输出电平
  108. * @param Port 端口号
  109. * @param Pins Pin序号组合
  110. * @return 无
  111. */
  112. void GPIO_ToggleMulti(uint32_t Port, uint32_t Pins);
  113. void GPIO_OutPulse(uint32_t Pin, uint8_t *Data, uint16_t BitLen, uint16_t Delay);
  114. void GPIO_ExtiSetCB(uint32_t Pin, CBFuncEx_t CB, void *pParam);
  115. void GPIO_ODConfig(uint32_t Pin, uint8_t InitValue);
  116. #endif