lib_gpio.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /***************************************************************
  2. *Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd.
  3. *文件名: lib_gpio.h
  4. *作 者: Liut
  5. *版 本: V1.00
  6. *日 期: 2017/07/14
  7. *描 述: GPIO模块及外部中断、按键中断库函数头文件
  8. *备 注: 适用于 ES8P508x芯片
  9. 本软件仅供学习和演示使用,对用户直接引用代码所带来的风险或后果不承担任何法律责任。
  10. ***************************************************************/
  11. #ifndef __LIBGPIO_H__
  12. #define __LIBGPIO_H__
  13. #include "ES8P508x.h"
  14. #include "type.h"
  15. /*状态定义*/
  16. /*端口定义*/
  17. typedef enum
  18. {
  19. GPIOA = 0x0 ,
  20. GPIOB = 0x1 ,
  21. }GPIO_TYPE;
  22. /*引脚定义*/
  23. typedef enum
  24. {
  25. GPIO_Pin_0 = 0x00,
  26. GPIO_Pin_1 = 0x01,
  27. GPIO_Pin_2 = 0x02,
  28. GPIO_Pin_3 = 0x03,
  29. GPIO_Pin_4 = 0x04,
  30. GPIO_Pin_5 = 0x05,
  31. GPIO_Pin_6 = 0x06,
  32. GPIO_Pin_7 = 0x07,
  33. GPIO_Pin_8 = 0x08,
  34. GPIO_Pin_9 = 0x09,
  35. GPIO_Pin_10 = 0x0A,
  36. GPIO_Pin_11 = 0x0B,
  37. GPIO_Pin_12 = 0x0C,
  38. GPIO_Pin_13 = 0x0D,
  39. GPIO_Pin_14 = 0x0E,
  40. GPIO_Pin_15 = 0x0F,
  41. GPIO_Pin_16 = 0x10,
  42. GPIO_Pin_17 = 0x11,
  43. GPIO_Pin_18 = 0x12,
  44. GPIO_Pin_19 = 0x13,
  45. GPIO_Pin_20 = 0x14,
  46. GPIO_Pin_21 = 0x15,
  47. GPIO_Pin_22 = 0x16,
  48. GPIO_Pin_23 = 0x17,
  49. GPIO_Pin_24 = 0x18,
  50. GPIO_Pin_25 = 0x19,
  51. GPIO_Pin_26 = 0x1A,
  52. GPIO_Pin_27 = 0x1B,
  53. GPIO_Pin_28 = 0x1C,
  54. GPIO_Pin_29 = 0x1D,
  55. GPIO_Pin_30 = 0x1E,
  56. GPIO_Pin_31 = 0x1F,
  57. }GPIO_TYPE_PIN;
  58. /* 引脚功能选择 */
  59. typedef enum
  60. {
  61. GPIO_Func_0 = 0x0 ,
  62. GPIO_Func_1 = 0x1 ,
  63. GPIO_Func_2 = 0x2 ,
  64. GPIO_Func_3 = 0x3 ,
  65. }GPIO_TYPE_FUNC;
  66. /* 引脚方向选择 */
  67. typedef enum
  68. {
  69. GPIO_Dir_Out = 0x0 ,
  70. GPIO_Dir_In = 0x1 ,
  71. }GPIO_TYPE_DIR;
  72. /* 引脚输出电流驱动能力选择 */
  73. typedef enum
  74. {
  75. GPIO_DS_Output_Normal = 0, // 普通电流输出
  76. GPIO_DS_Output_Strong = 1, // 强电流输出
  77. } GPIO_TYPE_DS;
  78. /* 引脚信号类型 */
  79. typedef enum {
  80. GPIO_Pin_Signal_Digital = 0, // 数字信号引脚
  81. GPIO_Pin_Signal_Analog = 1, // 模拟信号引脚
  82. } GPIO_Pin_Signal;
  83. /* 引脚输入弱上拉使能 */
  84. typedef enum {
  85. GPIO_PUE_Input_Disable = 0, // 弱上拉禁止
  86. GPIO_PUE_Input_Enable = 1, // 弱上拉使能
  87. } GPIO_PUE_Input;
  88. /* 引脚输入弱下拉使能 */
  89. typedef enum {
  90. GPIO_PDE_Input_Disable = 0, // 弱下拉禁止
  91. GPIO_PDE_Input_Enable = 1, // 弱下拉使能
  92. } GPIO_PDE_Input;
  93. /* 引脚输出开漏使能位 */
  94. typedef enum {
  95. GPIO_ODE_Output_Disable = 0, // 开漏禁止
  96. GPIO_ODE_Output_Enable = 1, // 开漏使能
  97. } GPIO_ODE_Output;
  98. /* GPIO初始化配置结构体定义 */
  99. typedef struct
  100. {
  101. GPIO_Pin_Signal GPIO_Signal; /* 引脚上的信号类型,只有模拟和数字两种 */
  102. GPIO_TYPE_FUNC GPIO_Func; //引脚功能选择
  103. GPIO_TYPE_DIR GPIO_Direction; //方向选择
  104. GPIO_PUE_Input GPIO_PUEN; //上拉使能
  105. GPIO_PDE_Input GPIO_PDEN; //下拉使能
  106. GPIO_ODE_Output GPIO_OD; //输出模式开漏使能
  107. GPIO_TYPE_DS GPIO_DS; //驱动电流控制
  108. }GPIO_InitStruType;
  109. /* PINT */
  110. typedef enum
  111. {
  112. PINT0 = 0x0 ,
  113. PINT1 = 0x1 ,
  114. PINT2 = 0x2 ,
  115. PINT3 = 0x3 ,
  116. PINT4 = 0x4 ,
  117. PINT5 = 0x5 ,
  118. PINT6 = 0x6 ,
  119. PINT7 = 0x7 ,
  120. }PINT_TYPE;
  121. /* PINT SEL */
  122. typedef enum
  123. {
  124. PINT_SEL0 = 0x0 ,
  125. PINT_SEL1 = 0x1 ,
  126. PINT_SEL2 = 0x2 ,
  127. PINT_SEL3 = 0x3 ,
  128. PINT_SEL4 = 0x4 ,
  129. PINT_SEL5 = 0x5 ,
  130. PINT_SEL6 = 0x6 ,
  131. PINT_SEL7 = 0x7 ,
  132. }PINT_TYPE_SEL;
  133. /* PINT Trigger */
  134. typedef enum
  135. {
  136. PINT_Trig_Rise = 0x0 ,
  137. PINT_Trig_Fall = 0x1 ,
  138. PINT_Trig_High = 0x2 ,
  139. PINT_Trig_Low = 0x3 ,
  140. PINT_Trig_Change = 0x4 ,
  141. }PINT_TYPE_TRIG;
  142. /* PINT中断标志 */
  143. typedef enum
  144. {
  145. PINT_IT_PINT0 = 0x01 ,
  146. PINT_IT_PINT1 = 0x02 ,
  147. PINT_IT_PINT2 = 0x04 ,
  148. PINT_IT_PINT3 = 0x08 ,
  149. PINT_IT_PINT4 = 0x10 ,
  150. PINT_IT_PINT5 = 0x20 ,
  151. PINT_IT_PINT6 = 0x40 ,
  152. PINT_IT_PINT7 = 0x80 ,
  153. PINT_IT_PINTAll = 0xFF ,
  154. }PINT_TYPE_IT;
  155. /* PINT使能控制 */
  156. #define PINT0_Enable() (GPIO->PINTIE.PINTIE |= 0X1)
  157. #define PINT1_Enable() (GPIO->PINTIE.PINTIE |= 0x2)
  158. #define PINT2_Enable() (GPIO->PINTIE.PINTIE |= 0x4)
  159. #define PINT3_Enable() (GPIO->PINTIE.PINTIE |= 0x8)
  160. #define PINT4_Enable() (GPIO->PINTIE.PINTIE |= 0x10)
  161. #define PINT5_Enable() (GPIO->PINTIE.PINTIE |= 0x20)
  162. #define PINT6_Enable() (GPIO->PINTIE.PINTIE |= 0x40)
  163. #define PINT7_Enable() (GPIO->PINTIE.PINTIE |= 0x80)
  164. #define PINT0_Disable() (GPIO->PINTIE.PINTIE &= ~0x01)
  165. #define PINT1_Disable() (GPIO->PINTIE.PINTIE &= ~0x02)
  166. #define PINT2_Disable() (GPIO->PINTIE.PINTIE &= ~0x04)
  167. #define PINT3_Disable() (GPIO->PINTIE.PINTIE &= ~0x08)
  168. #define PINT4_Disable() (GPIO->PINTIE.PINTIE &= ~0x10)
  169. #define PINT5_Disable() (GPIO->PINTIE.PINTIE &= ~0x20)
  170. #define PINT6_Disable() (GPIO->PINTIE.PINTIE &= ~0x40)
  171. #define PINT7_Disable() (GPIO->PINTIE.PINTIE &= ~0x80)
  172. /* PINT屏蔽使能控制 */
  173. #define PINT0_MaskEnable() (GPIO->PINTIE.PMASK |= 0X01)
  174. #define PINT1_MaskEnable() (GPIO->PINTIE.PMASK |= 0x02)
  175. #define PINT2_MaskEnable() (GPIO->PINTIE.PMASK |= 0x04)
  176. #define PINT3_MaskEnable() (GPIO->PINTIE.PMASK |= 0x08)
  177. #define PINT4_MaskEnable() (GPIO->PINTIE.PMASK |= 0x10)
  178. #define PINT5_MaskEnable() (GPIO->PINTIE.PMASK |= 0x20)
  179. #define PINT6_MaskEnable() (GPIO->PINTIE.PMASK |= 0x40)
  180. #define PINT7_MaskEnable() (GPIO->PINTIE.PMASK |= 0x80)
  181. #define PINT0_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x01)
  182. #define PINT1_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x02)
  183. #define PINT2_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x04)
  184. #define PINT3_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x08)
  185. #define PINT4_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x10)
  186. #define PINT5_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x20)
  187. #define PINT6_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x40)
  188. #define PINT7_MaskDisable() (GPIO->PINTIE.PMASK &= ~0x80)
  189. /* PINT清除所有中断标记 */
  190. #define PINT_ClearAllITPending() (GPIO->PIF.Word = (uint32_t)0xff)
  191. void GPIO_Init(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_InitStruType* GPIO_InitStruct);
  192. void GPIO_Write(GPIO_TYPE GPIOx, uint32_t Value);
  193. uint32_t GPIO_Read(GPIO_TYPE GPIOx);
  194. PinStatus GPIO_ReadBit(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx);
  195. void GPIOA_SetBit(GPIO_TYPE_PIN PINx);
  196. void GPIOA_ResetBit(GPIO_TYPE_PIN PINx);
  197. void GPIOA_ToggleBit(GPIO_TYPE_PIN PINx);
  198. void GPIOB_SetBit(GPIO_TYPE_PIN PINx);
  199. void GPIOB_ResetBit(GPIO_TYPE_PIN PINx);
  200. void GPIOB_ToggleBit(GPIO_TYPE_PIN PINx);
  201. void GPIOA_SetDirection(GPIO_TYPE_PIN PINx, GPIO_TYPE_DIR Dir_Type);
  202. void GPIOB_SetDirection(GPIO_TYPE_PIN PINx, GPIO_TYPE_DIR Dir_Type);
  203. void PINT_Config(PINT_TYPE PINTx, PINT_TYPE_SEL SELx, PINT_TYPE_TRIG TRIGx);
  204. void GPIO_SetSingalTypeFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_Pin_Signal GPIO_Signal);
  205. void GPIO_SetDirRegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_TYPE_DIR Dir);
  206. void GPIO_SetODERegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_ODE_Output ODE);
  207. void GPIO_SetDSRegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_TYPE_DS DS);
  208. void GPIO_SetPUERegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_PUE_Input PUE);
  209. void GPIO_SetPDERegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_PDE_Input PDE);
  210. void GPIO_SetFuncxRegFromPin(GPIO_TYPE GPIOx,GPIO_TYPE_PIN PINx, GPIO_TYPE_FUNC Func);
  211. FlagStatus PINT_GetIFStatus(PINT_TYPE_IT PINT_Flag);
  212. FlagStatus PINT_GetITStatus(PINT_TYPE_IT PINT_Flag);
  213. void PINT_ClearITPendingBit(PINT_TYPE_IT PINT_Flag);
  214. #endif