1 /**
2 * @file xmc1_gpio.h
3 * @date 2015-06-20
4 *
5 * @cond
6 *********************************************************************************************************************
7 * XMClib v2.1.24 - XMC Peripheral Driver Library
8 *
9 * Copyright (c) 2015-2019, Infineon Technologies AG
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
13 * following conditions are met:
14 *
15 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided with the distribution.
20 *
21 * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
22 * products derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
33 * Infineon Technologies AG dave@infineon.com).
34 *********************************************************************************************************************
35 *
36 * Change History
37 * --------------
38 *
39 * 2015-02-20:
40 * - Initial draft<br>
41 *
42 * 2015-06-20:
43 * - Removed version macros and declaration of GetDriverVersion API
44 *
45 * @endcond
46 *
47 */
48
49 #ifndef XMC1_GPIO_H
50 #define XMC1_GPIO_H
51
52 /**********************************************************************************************************************
53 * HEADER FILES
54 *********************************************************************************************************************/
55
56 #include "xmc_common.h"
57
58 #if UC_FAMILY == XMC1
59
60 #include "xmc1_gpio_map.h"
61
62 /**
63 * @addtogroup XMClib XMC Peripheral Library
64 * @{
65 */
66
67 /**
68 * @addtogroup GPIO
69 * @{
70 */
71
72 /**********************************************************************************************************************
73 * MACROS
74 *********************************************************************************************************************/
75
76 #if defined(PORT0)
77 #define XMC_GPIO_PORT0 ((XMC_GPIO_PORT_t *) PORT0_BASE)
78 #define XMC_GPIO_CHECK_PORT0(port) (port == XMC_GPIO_PORT0)
79 #else
80 #define XMC_GPIO_CHECK_PORT0(port) 0
81 #endif
82
83 #if defined(PORT1)
84 #define XMC_GPIO_PORT1 ((XMC_GPIO_PORT_t *) PORT1_BASE)
85 #define XMC_GPIO_CHECK_PORT1(port) (port == XMC_GPIO_PORT1)
86 #else
87 #define XMC_GPIO_CHECK_PORT1(port) 0
88 #endif
89
90 #if defined(PORT2)
91 #define XMC_GPIO_PORT2 ((XMC_GPIO_PORT_t *) PORT2_BASE)
92 #define XMC_GPIO_CHECK_PORT2(port) (port == XMC_GPIO_PORT2)
93 #else
94 #define XMC_GPIO_CHECK_PORT2(port) 0
95 #endif
96
97 #if defined(PORT3)
98 #define XMC_GPIO_PORT3 ((XMC_GPIO_PORT_t *) PORT3_BASE)
99 #define XMC_GPIO_CHECK_PORT3(port) (port == XMC_GPIO_PORT3)
100 #else
101 #define XMC_GPIO_CHECK_PORT3(port) 0
102 #endif
103
104 #if defined(PORT4)
105 #define XMC_GPIO_PORT4 ((XMC_GPIO_PORT_t *) PORT4_BASE)
106 #define XMC_GPIO_CHECK_PORT4(port) (port == XMC_GPIO_PORT4)
107 #else
108 #define XMC_GPIO_CHECK_PORT4(port) 0
109 #endif
110
111 #define XMC_GPIO_CHECK_PORT(port) (XMC_GPIO_CHECK_PORT0(port) || \
112 XMC_GPIO_CHECK_PORT1(port) || \
113 XMC_GPIO_CHECK_PORT2(port) || \
114 XMC_GPIO_CHECK_PORT3(port) || \
115 XMC_GPIO_CHECK_PORT4(port))
116
117 #define XMC_GPIO_CHECK_OUTPUT_PORT(port) XMC_GPIO_CHECK_PORT(port)
118
119 #define XMC_GPIO_CHECK_ANALOG_PORT(port) (port == XMC_GPIO_PORT2)
120
121 #define XMC_GPIO_CHECK_INPUT_HYSTERESIS(hysteresis) ((hysteresis == XMC_GPIO_INPUT_HYSTERESIS_STANDARD) || \
122 (hysteresis == XMC_GPIO_INPUT_HYSTERESIS_LARGE))
123
124 /**********************************************************************************************************************
125 * ENUMS
126 *********************************************************************************************************************/
127 /**
128 * Defines the direction and characteristics of a pin. Use type \a XMC_GPIO_MODE_t for this enum. For the operation
129 * with alternate functions, the port pins are directly connected to input or output functions of the on-chip periphery.
130 */
131 typedef enum XMC_GPIO_MODE
132 {
133 XMC_GPIO_MODE_INPUT_TRISTATE = 0x0UL << PORT_IOCR_PC_Pos, /**< No internal pull device active */
134 XMC_GPIO_MODE_INPUT_PULL_DOWN = 0x1UL << PORT_IOCR_PC_Pos, /**< Internal pull-down device active */
135 XMC_GPIO_MODE_INPUT_PULL_UP = 0x2UL << PORT_IOCR_PC_Pos, /**< Internal pull-up device active */
136 XMC_GPIO_MODE_INPUT_SAMPLING = 0x3UL << PORT_IOCR_PC_Pos, /**< No internal pull device active; Pn_OUTx continuously samples the input value */
137 XMC_GPIO_MODE_INPUT_INVERTED_TRISTATE = 0x4UL << PORT_IOCR_PC_Pos, /**< Inverted no internal pull device active */
138 XMC_GPIO_MODE_INPUT_INVERTED_PULL_DOWN = 0x5UL << PORT_IOCR_PC_Pos, /**< Inverted internal pull-down device active */
139 XMC_GPIO_MODE_INPUT_INVERTED_PULL_UP = 0x6UL << PORT_IOCR_PC_Pos, /**< Inverted internal pull-up device active */
140 XMC_GPIO_MODE_INPUT_INVERTED_SAMPLING = 0x7UL << PORT_IOCR_PC_Pos, /**< Inverted no internal pull device active;Pn_OUTx continuously samples the input value */
141 XMC_GPIO_MODE_OUTPUT_PUSH_PULL = 0x80UL, /**< Push-pull general-purpose output */
142 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN = 0xc0UL, /**< Open-drain general-purpose output */
143 XMC_GPIO_MODE_OUTPUT_ALT1 = 0x1UL << PORT_IOCR_PC_Pos,
144 XMC_GPIO_MODE_OUTPUT_ALT2 = 0x2UL << PORT_IOCR_PC_Pos,
145 XMC_GPIO_MODE_OUTPUT_ALT3 = 0x3UL << PORT_IOCR_PC_Pos,
146 XMC_GPIO_MODE_OUTPUT_ALT4 = 0x4UL << PORT_IOCR_PC_Pos,
147 XMC_GPIO_MODE_OUTPUT_ALT5 = 0x5UL << PORT_IOCR_PC_Pos,
148 XMC_GPIO_MODE_OUTPUT_ALT6 = 0x6UL << PORT_IOCR_PC_Pos,
149 XMC_GPIO_MODE_OUTPUT_ALT7 = 0x7UL << PORT_IOCR_PC_Pos,
150 #if (UC_SERIES == XMC14)
151 XMC_GPIO_MODE_OUTPUT_ALT8 = 0x8UL << PORT_IOCR_PC_Pos,
152 XMC_GPIO_MODE_OUTPUT_ALT9 = 0x9UL << PORT_IOCR_PC_Pos,
153 #endif
154 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT1, /**< Push-pull alternate output function 1 */
155 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT2, /**< Push-pull alternate output function 2 */
156 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT3 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT3, /**< Push-pull alternate output function 3 */
157 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT4 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT4, /**< Push-pull alternate output function 4 */
158 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT5 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT5, /**< Push-pull alternate output function 5 */
159 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT6 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT6, /**< Push-pull alternate output function 6 */
160 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT7, /**< Push-pull alternate output function 7 */
161 #if (UC_SERIES == XMC14)
162 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT8 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT8, /**< Push-pull alternate output function 8 */
163 XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT9 = XMC_GPIO_MODE_OUTPUT_PUSH_PULL | XMC_GPIO_MODE_OUTPUT_ALT9, /**< Push-pull alternate output function 9 */
164 #endif
165 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT1 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT1, /**< Open drain alternate output function 1 */
166 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT2 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT2, /**< Open drain alternate output function 2 */
167 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT3 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT3, /**< Open drain alternate output function 3 */
168 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT4 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT4, /**< Open drain alternate output function 4 */
169 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT5 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT5, /**< Open drain alternate output function 5 */
170 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT6 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT6, /**< Open drain alternate output function 6 */
171 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT7 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT7, /**< Open drain alternate output function 7 */
172 #if (UC_SERIES == XMC14)
173 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT8 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT8, /**< Open drain alternate output function 8 */
174 XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT9 = XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN | XMC_GPIO_MODE_OUTPUT_ALT9 /**< Open drain alternate output function 9 */
175 #endif
176 } XMC_GPIO_MODE_t;
177
178 /**
179 * Configures input hysteresis mode of pin. Use type \a XMC_GPIO_INPUT_HYSTERESIS_t for this enum.
180 * Selecting the appropriate pad hysteresis allows optimized pad oscillation behavior
181 * for touch-sensing applications.
182 */
183 typedef enum XMC_GPIO_INPUT_HYSTERESIS
184 {
185 XMC_GPIO_INPUT_HYSTERESIS_STANDARD = 0x0U, /**< Standard hysteresis */
186 XMC_GPIO_INPUT_HYSTERESIS_LARGE = 0x4U /**< Large hysteresis */
187 } XMC_GPIO_INPUT_HYSTERESIS_t;
188
189
190 /**********************************************************************************************************************
191 * DATA STRUCTURES
192 *********************************************************************************************************************/
193 /**
194 * Structure points port hardware registers. Use type XMC_GPIO_PORT_t for this structure.
195 */
196 typedef struct XMC_GPIO_PORT {
197 __IO uint32_t OUT; /**< The port output register determines the value of a GPIO pin when it is
198 selected by Pn_IOCRx as output */
199 __O uint32_t OMR; /**< The port output modification register contains control bits that make it
200 possible to individually set, reset, or toggle the logic state of a single port
201 line*/
202 __I uint32_t RESERVED0[2];
203 __IO uint32_t IOCR[4]; /**< The port input/output control registers select the digital output and input
204 driver functionality and characteristics of a GPIO port pin */
205 __I uint32_t RESERVED1;
206 __I uint32_t IN; /**< The logic level of a GPIO pin can be read via the read-only port input register
207 Pn_IN */
208 __I uint32_t RESERVED2[6];
209 __IO uint32_t PHCR[2]; /**< Pad hysteresis control register */
210 __I uint32_t RESERVED3[6];
211 __IO uint32_t PDISC; /**< Pin Function Decision Control Register is to disable/enable the digital pad
212 structure in shared analog and digital ports*/
213 __I uint32_t RESERVED4[3];
214 __IO uint32_t PPS; /**< Pin Power Save Register */
215 __IO uint32_t HWSEL; /**< Pin Hardware Select Register */
216 } XMC_GPIO_PORT_t;
217
218 /**
219 * Structure initializes port pin. Use type XMC_GPIO_CONFIG_t for this structure.
220 */
221 typedef struct XMC_GPIO_CONFIG
222 {
223 XMC_GPIO_MODE_t mode; /**< Defines the direction and characteristics of a pin */
224 XMC_GPIO_INPUT_HYSTERESIS_t input_hysteresis; /**< Defines input pad hysteresis of a pin */
225 XMC_GPIO_OUTPUT_LEVEL_t output_level; /**< Defines output level of a pin */
226 } XMC_GPIO_CONFIG_t;
227
228 /**********************************************************************************************************************
229 * API PROTOTYPES
230 *********************************************************************************************************************/
XMC_GPIO_IsModeValid(XMC_GPIO_MODE_t mode)231 __STATIC_INLINE bool XMC_GPIO_IsModeValid(XMC_GPIO_MODE_t mode)
232 {
233 return ((mode == XMC_GPIO_MODE_INPUT_TRISTATE) ||
234 (mode == XMC_GPIO_MODE_INPUT_PULL_DOWN) ||
235 (mode == XMC_GPIO_MODE_INPUT_PULL_UP) ||
236 (mode == XMC_GPIO_MODE_INPUT_SAMPLING) ||
237 (mode == XMC_GPIO_MODE_INPUT_INVERTED_TRISTATE) ||
238 (mode == XMC_GPIO_MODE_INPUT_INVERTED_PULL_DOWN) ||
239 (mode == XMC_GPIO_MODE_INPUT_INVERTED_PULL_UP) ||
240 (mode == XMC_GPIO_MODE_INPUT_INVERTED_SAMPLING) ||
241 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL) ||
242 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1) ||
243 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2) ||
244 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT3) ||
245 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT4) ||
246 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT5) ||
247 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT6) ||
248 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7) ||
249 #if (UC_SERIES == XMC14)
250 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT8) ||
251 (mode == XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT9) ||
252 #endif
253 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN) ||
254 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT1) ||
255 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT2) ||
256 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT3) ||
257 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT4) ||
258 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT5) ||
259 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT6) ||
260 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT7)
261 #if (UC_SERIES == XMC14)
262 || (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT8) ||
263 (mode == XMC_GPIO_MODE_OUTPUT_OPEN_DRAIN_ALT9)
264 #endif
265 );
266 }
267
268
269 /**
270 * @brief Sets pad hysteresis.
271 * @param port Constant pointer pointing to GPIO port, to access hardware register Pn_PHCR.
272 * @param pin Port pin number.
273 * @param hysteresis input hysteresis selection. Refer data structure @ref XMC_GPIO_INPUT_HYSTERESIS_t
274 * for details.
275 *
276 * @return None
277 *
278 * \par<b>Description:</b><br>
279 * Sets port pin input hysteresis. It configures hardware registers Pn_PHCR.\a hysteresis is initially configured during
280 * initialization in XMC_GPIO_Init(). Call this API to alter pad hysteresis as needed later in the program.
281 *
282 * \par<b>Related APIs:</b><BR>
283 * None
284 *
285 * \par<b>Note:</b><br>
286 * Prior to this api, user has to configure port pin to input mode using XMC_GPIO_SetMode().
287 *
288 */
289
290 void XMC_GPIO_SetInputHysteresis(XMC_GPIO_PORT_t *const port,
291 const uint8_t pin,
292 const XMC_GPIO_INPUT_HYSTERESIS_t hysteresis);
293
294 /**
295 * @} (end addtogroup GPIO)
296 */
297
298 /**
299 * @} (end addtogroup XMClib)
300 */
301
302 #endif /* UC_FAMILY == XMC1 */
303
304 #endif /* XMC1_GPIO_H */
305
306