1 /*!
2  * @file        apm32f0xx_gpio.h
3  *
4  * @brief       This file contains all the functions prototypes for the GPIO firmware library
5  *
6  * @version     V1.0.3
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 
27 /* Define to prevent recursive inclusion */
28 #ifndef __APM32F0XX_GPIO_H
29 #define __APM32F0XX_GPIO_H
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /* Includes */
36 #include "apm32f0xx.h"
37 
38 /** @addtogroup APM32F0xx_StdPeriphDriver
39   @{
40 */
41 
42 /** @addtogroup GPIO_Driver
43   @{
44 */
45 
46 /** @defgroup GPIO_Macros Macros
47   @{
48 */
49 
50 /**@} end of group GPIO_Macros */
51 
52 /** @defgroup GPIO_Enumerations Enumerations
53   @{
54 */
55 
56 /**
57  * @brief   Configuration Mode enumeration
58  */
59 typedef enum
60 {
61     GPIO_MODE_IN  = 0x00,     /*!< GPIO Input Mode */
62     GPIO_MODE_OUT = 0x01,     /*!< GPIO Output Mode */
63     GPIO_MODE_AF  = 0x02,     /*!< GPIO Alternate function Mode */
64     GPIO_MODE_AN  = 0x03,     /*!< GPIO Analog In/Out Mode */
65 } GPIO_MODE_T;
66 
67 /**
68  * @brief   Output type enumeration
69  */
70 typedef enum
71 {
72     GPIO_OUT_TYPE_PP = 0x00,      /*!< General purpose output push-pull */
73     GPIO_OUT_TYPE_OD = 0x01,      /*!< General purpose output Open-drain */
74 } GPIO_OUT_TYPE_T;
75 
76 /**
77  * @brief   GPIO Output Maximum frequency selection
78  */
79 typedef enum
80 {
81     GPIO_SPEED_2MHz  = 0x00,      /*!< Output speed up to 2 MHz */
82     GPIO_SPEED_10MHz = 0x01,      /*!< Output speed up to 10 MHz */
83     GPIO_SPEED_50MHz = 0x03,      /*!< Output speed up to 50 MHz */
84 } GPIO_SPEED_T;
85 
86 /**
87  * @brief   Configuration Pull-Up Pull-Down enumeration
88  */
89 typedef enum
90 {
91     GPIO_PUPD_NO = 0x00,          /*!< GPIO no pull mode */
92     GPIO_PUPD_PU = 0x01,          /*!< GPIO pull-up mode */
93     GPIO_PUPD_PD = 0x02,          /*!< GPIO pull-down mode */
94 } GPIO_PUPD_T;
95 
96 /**
97  * @brief   Bit SET and Bit RESET enumeration
98  */
99 typedef enum
100 {
101     Bit_RESET,
102     Bit_SET
103 } GPIO_BSRET_T;
104 
105 /**
106  * @brief    Definition of the GPIO pins
107  */
108 typedef enum
109 {
110     GPIO_PIN_0   = ((uint16_t)BIT0),    /*!< GPIO pin 0 selected */
111     GPIO_PIN_1   = ((uint16_t)BIT1),    /*!< GPIO pin 1 selected */
112     GPIO_PIN_2   = ((uint16_t)BIT2),    /*!< GPIO pin 2 selected */
113     GPIO_PIN_3   = ((uint16_t)BIT3),    /*!< GPIO pin 3 selected */
114     GPIO_PIN_4   = ((uint16_t)BIT4),    /*!< GPIO pin 4 selected */
115     GPIO_PIN_5   = ((uint16_t)BIT5),    /*!< GPIO pin 5 selected */
116     GPIO_PIN_6   = ((uint16_t)BIT6),    /*!< GPIO pin 6 selected */
117     GPIO_PIN_7   = ((uint16_t)BIT7),    /*!< GPIO pin 7 selected */
118     GPIO_PIN_8   = ((uint16_t)BIT8),    /*!< GPIO pin 8 selected */
119     GPIO_PIN_9   = ((uint16_t)BIT9),    /*!< GPIO pin 9 selected */
120     GPIO_PIN_10  = ((uint16_t)BIT10),   /*!< GPIO pin 10 selected */
121     GPIO_PIN_11  = ((uint16_t)BIT11),   /*!< GPIO pin 11 selected */
122     GPIO_PIN_12  = ((uint16_t)BIT12),   /*!< GPIO pin 12 selected */
123     GPIO_PIN_13  = ((uint16_t)BIT13),   /*!< GPIO pin 13 selected */
124     GPIO_PIN_14  = ((uint16_t)BIT14),   /*!< GPIO pin 14 selected */
125     GPIO_PIN_15  = ((uint16_t)BIT15),   /*!< GPIO pin 15 selected */
126     GPIO_PIN_ALL = ((uint32_t)0XFFFF),  /*!< GPIO all pins selected */
127 } GPIO_PIN_T;
128 
129 /**
130  * @brief   GPIO Pin sources
131  */
132 typedef enum
133 {
134     GPIO_PIN_SOURCE_0   = ((uint8_t)0x00),  /*!< GPIO pin source 0 */
135     GPIO_PIN_SOURCE_1   = ((uint8_t)0x01),  /*!< GPIO pin source 1 */
136     GPIO_PIN_SOURCE_2   = ((uint8_t)0x02),  /*!< GPIO pin source 2 */
137     GPIO_PIN_SOURCE_3   = ((uint8_t)0x03),  /*!< GPIO pin source 3 */
138     GPIO_PIN_SOURCE_4   = ((uint8_t)0x04),  /*!< GPIO pin source 4 */
139     GPIO_PIN_SOURCE_5   = ((uint8_t)0x05),  /*!< GPIO pin source 5 */
140     GPIO_PIN_SOURCE_6   = ((uint8_t)0x06),  /*!< GPIO pin source 6 */
141     GPIO_PIN_SOURCE_7   = ((uint8_t)0x07),  /*!< GPIO pin source 7 */
142     GPIO_PIN_SOURCE_8   = ((uint8_t)0x08),  /*!< GPIO pin source 8 */
143     GPIO_PIN_SOURCE_9   = ((uint8_t)0x09),  /*!< GPIO pin source 9 */
144     GPIO_PIN_SOURCE_10  = ((uint8_t)0x0A),  /*!< GPIO pin source 10 */
145     GPIO_PIN_SOURCE_11  = ((uint8_t)0x0B),  /*!< GPIO pin source 11 */
146     GPIO_PIN_SOURCE_12  = ((uint8_t)0x0C),  /*!< GPIO pin source 12 */
147     GPIO_PIN_SOURCE_13  = ((uint8_t)0x0D),  /*!< GPIO pin source 13 */
148     GPIO_PIN_SOURCE_14  = ((uint8_t)0x0E),  /*!< GPIO pin source 14 */
149     GPIO_PIN_SOURCE_15  = ((uint8_t)0x0F),  /*!< GPIO pin source 15 */
150 } GPIO_PIN_SOURCE_T;
151 
152 /**
153  * @brief   gpio alternate function define
154  */
155 typedef enum
156 {
157     GPIO_AF_PIN0 = ((uint8_t)0x00),  /*!< GPIO alternate function pin 0 */
158     GPIO_AF_PIN1 = ((uint8_t)0x01),  /*!< GPIO alternate function pin 1 */
159     GPIO_AF_PIN2 = ((uint8_t)0x02),  /*!< GPIO alternate function pin 2 */
160     GPIO_AF_PIN3 = ((uint8_t)0x03),  /*!< GPIO alternate function pin 3 */
161     GPIO_AF_PIN4 = ((uint8_t)0x04),  /*!< GPIO alternate function pin 4 */
162     GPIO_AF_PIN5 = ((uint8_t)0x05),  /*!< GPIO alternate function pin 5 */
163     GPIO_AF_PIN6 = ((uint8_t)0x06),  /*!< GPIO alternate function pin 6 */
164     GPIO_AF_PIN7 = ((uint8_t)0x07),  /*!< GPIO alternate function pin 7 */
165 } GPIO_AF_T;
166 
167 /**@} end of group GPIO_Enumerations */
168 
169 /** @defgroup GPIO_Structures Structures
170   @{
171 */
172 
173 /**
174  * @brief   GPIO Config structure definition
175  */
176 typedef struct
177 {
178     uint16_t         pin;      /*!< Specifies the GPIO pins to be configured */
179     GPIO_MODE_T      mode;     /*!< Specifies the operating mode for the selected pins */
180     GPIO_OUT_TYPE_T  outtype;  /*!< Specifies the speed for the selected pins */
181     GPIO_SPEED_T     speed;    /*!< Specifies the operating output type for the selected pins */
182     GPIO_PUPD_T      pupd;     /*!< Specifies the operating Pull-up/Pull down for the selected pins */
183 } GPIO_Config_T;
184 
185 /**@} end of group GPIO_Structures */
186 
187 /** @defgroup GPIO_Variables Variables
188   @{
189 */
190 
191 /**@} end of group GPIO_Variables*/
192 
193 /** @defgroup GPIO_Functions Functions
194   @{
195 */
196 
197 /* Reset and common Configuration */
198 void GPIO_Reset(GPIO_T* port);
199 void GPIO_Config(GPIO_T* port, GPIO_Config_T* gpioConfig);
200 void GPIO_ConfigStructInit(GPIO_Config_T* gpioConfig);
201 
202 /* GPIO Lock functions */
203 void GPIO_ConfigPinLock(GPIO_T* port, uint16_t pin);
204 
205 /* GPIO Read functions */
206 uint16_t GPIO_ReadOutputPort(GPIO_T* port);
207 uint16_t GPIO_ReadInputPort(GPIO_T* port);
208 uint8_t GPIO_ReadInputBit(GPIO_T* port, uint16_t pin);
209 uint8_t GPIO_ReadOutputBit(GPIO_T* port, uint16_t pin);
210 
211 /* GPIO Write functions */
212 void GPIO_SetBit(GPIO_T* port, uint16_t pin);
213 void GPIO_ClearBit(GPIO_T* port, uint16_t pin);
214 void GPIO_WriteBitValue(GPIO_T* port, uint16_t pin, GPIO_BSRET_T bitVal);
215 void GPIO_WriteOutputPort(GPIO_T* port, uint16_t portValue);
216 
217 /* GPIO Other functions */
218 void GPIO_ConfigPinAF(GPIO_T* port, GPIO_PIN_SOURCE_T pinSource, GPIO_AF_T afPin);
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif /* __APM32F0xx_GPIO_H */
225 
226 /**@} end of group GPIO_Functions */
227 /**@} end of group GPIO_Driver */
228 /**@} end of group APM32F0xx_StdPeriphDriver */
229