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