air105_gpio.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 __AIR105_GPIO_H
  22. #define __AIR105_GPIO_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "air105.h"
  28. /**
  29. * @brief Configuration Mode enumeration
  30. */
  31. typedef enum
  32. {
  33. GPIO_Mode_IN_FLOATING = 0x01,
  34. GPIO_Mode_IPU = 0x02,
  35. GPIO_Mode_Out_OD = 0x03,
  36. GPIO_Mode_Out_OD_PU = 0x04,
  37. GPIO_Mode_Out_PP = 0x05
  38. }GPIO_ModeTypeDef;
  39. #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN_FLOATING) || \
  40. ((MODE) == GPIO_Mode_IPU) || \
  41. ((MODE) == GPIO_Mode_Out_OD) || \
  42. ((MODE) == GPIO_Mode_Out_PP) || \
  43. ((MODE) == GPIO_Mode_Out_OD_PU))
  44. /**
  45. * @brief GPIO Remap Type definition
  46. */
  47. typedef enum
  48. {
  49. GPIO_Remap_0 = 0x01,
  50. GPIO_Remap_1 = 0x02,
  51. GPIO_Remap_2 = 0x03,
  52. GPIO_Remap_3 = 0x04,
  53. }GPIO_RemapTypeDef;
  54. #define IS_GET_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_0) || \
  55. ((REMAP) == GPIO_Remap_1) || \
  56. ((REMAP) == GPIO_Remap_2) || \
  57. ((REMAP) == GPIO_Remap_3) )
  58. /**
  59. * @brief GPIO Init structure definition
  60. */
  61. typedef struct
  62. {
  63. uint32_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
  64. This parameter can be any value of @ref GPIO_pins_define */
  65. GPIO_ModeTypeDef GPIO_Mode;
  66. GPIO_RemapTypeDef GPIO_Remap;
  67. }GPIO_InitTypeDef;
  68. /**
  69. * @brief Bit_SET and Bit_RESET enumeration
  70. */
  71. typedef enum
  72. {
  73. Bit_RESET = 0,
  74. Bit_SET
  75. }BitAction;
  76. /**
  77. * @}
  78. */
  79. /** @defgroup GPIO_Exported_Constants
  80. * @{
  81. */
  82. /** @defgroup GPIO_pins_define
  83. * @{
  84. */
  85. #define IS_GPIO_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
  86. ((PERIPH) == GPIOB) || \
  87. ((PERIPH) == GPIOC) || \
  88. ((PERIPH) == GPIOD) || \
  89. ((PERIPH) == GPIOE) || \
  90. ((PERIPH) == GPIOF))
  91. #define GPIO_Pin_0 ((uint16_t)0x0001) /*!< Pin 0 selected */
  92. #define GPIO_Pin_1 ((uint16_t)0x0002) /*!< Pin 1 selected */
  93. #define GPIO_Pin_2 ((uint16_t)0x0004) /*!< Pin 2 selected */
  94. #define GPIO_Pin_3 ((uint16_t)0x0008) /*!< Pin 3 selected */
  95. #define GPIO_Pin_4 ((uint16_t)0x0010) /*!< Pin 4 selected */
  96. #define GPIO_Pin_5 ((uint16_t)0x0020) /*!< Pin 5 selected */
  97. #define GPIO_Pin_6 ((uint16_t)0x0040) /*!< Pin 6 selected */
  98. #define GPIO_Pin_7 ((uint16_t)0x0080) /*!< Pin 7 selected */
  99. #define GPIO_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */
  100. #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */
  101. #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */
  102. #define GPIO_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */
  103. #define GPIO_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */
  104. #define GPIO_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */
  105. #define GPIO_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */
  106. #define GPIO_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */
  107. #define GPIO_Pin_All ((uint16_t)0xffff) /*!< Pin All selected */
  108. #define IS_GPIO_PIN(PIN) (((((PIN) & ~(uint16_t)0xFFFF)) == 0x00) && ((PIN) != (uint16_t)0x00))
  109. #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
  110. ((PIN) == GPIO_Pin_1) || \
  111. ((PIN) == GPIO_Pin_2) || \
  112. ((PIN) == GPIO_Pin_3) || \
  113. ((PIN) == GPIO_Pin_4) || \
  114. ((PIN) == GPIO_Pin_5) || \
  115. ((PIN) == GPIO_Pin_6) || \
  116. ((PIN) == GPIO_Pin_7) || \
  117. ((PIN) == GPIO_Pin_8) || \
  118. ((PIN) == GPIO_Pin_9) || \
  119. ((PIN) == GPIO_Pin_10) || \
  120. ((PIN) == GPIO_Pin_11) || \
  121. ((PIN) == GPIO_Pin_12) || \
  122. ((PIN) == GPIO_Pin_13) || \
  123. ((PIN) == GPIO_Pin_14) || \
  124. ((PIN) == GPIO_Pin_15))
  125. /**
  126. * @}
  127. */
  128. #define GPIO_PinSource0 0x00
  129. #define GPIO_PinSource1 0x01
  130. #define GPIO_PinSource2 0x02
  131. #define GPIO_PinSource3 0x03
  132. #define GPIO_PinSource4 0x04
  133. #define GPIO_PinSource5 0x05
  134. #define GPIO_PinSource6 0x06
  135. #define GPIO_PinSource7 0x07
  136. #define GPIO_PinSource8 0x08
  137. #define GPIO_PinSource9 0x09
  138. #define GPIO_PinSource10 0x0A
  139. #define GPIO_PinSource11 0x0B
  140. #define GPIO_PinSource12 0x0C
  141. #define GPIO_PinSource13 0x0D
  142. #define GPIO_PinSource14 0x0E
  143. #define GPIO_PinSource15 0x0F
  144. /** @defgroup GPIO_Port_Sources
  145. * @{
  146. */
  147. #define GPIO_PortSourceGPIOA ((uint32_t)0x00)
  148. #define GPIO_PortSourceGPIOB ((uint32_t)0x01)
  149. #define GPIO_PortSourceGPIOC ((uint32_t)0x02)
  150. #define GPIO_PortSourceGPIOD ((uint32_t)0x03)
  151. #define GPIO_PortSourceGPIOE ((uint32_t)0x04)
  152. #define GPIO_PortSourceGPIOF ((uint32_t)0x05)
  153. #define IS_GPIO_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
  154. ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
  155. ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
  156. ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
  157. ((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
  158. ((PORTSOURCE) == GPIO_PortSourceGPIOF))
  159. /**
  160. * @}
  161. */
  162. /** @defgroup GPIO_WakeMode
  163. * @{
  164. */
  165. typedef enum
  166. {
  167. GPIO_WakeMode_Now = (uint32_t)0x00,
  168. GPIO_WakeMode_AfterGlitch = (uint32_t)0x01
  169. }GPIO_WakeModeTypeDef;
  170. #define IS_GPIO_WAKE_MODE(MODE) (((MODE) == GPIO_WakeMode_Now) || \
  171. ((MODE) == GPIO_WakeMode_AfterGlitch))
  172. /**
  173. * @}
  174. */
  175. /** @defgroup GPIO_Exported_Functions
  176. * @{
  177. */
  178. void GPIO_DeInit(void);
  179. void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
  180. void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
  181. uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  182. uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
  183. uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  184. uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
  185. void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  186. void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
  187. void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
  188. void GPIO_PullUpCmd(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, FunctionalState NewState);
  189. void GPIO_PinRemapConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_RemapTypeDef GPIO_Remap);
  190. void GPIO_WakeEvenDeInit(void);
  191. void GPIO_WakeEvenConfig(uint32_t GPIO_PortSource, uint32_t GPIO_Pin, FunctionalState NewState);
  192. void GPIO_WakeModeConfig(GPIO_WakeModeTypeDef GPIO_WakeMode);
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #endif
  197. /************************** (C) COPYRIGHT Megahunt *****END OF FILE****/