2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
\r
3 * Copyright 2016-2018 NXP
\r
4 * All rights reserved.
\r
6 * SPDX-License-Identifier: BSD-3-Clause
\r
10 #define _LPC_GPIO_H_
\r
12 #include "fsl_common.h"
\r
15 * @addtogroup lpc_gpio
\r
21 /*******************************************************************************
\r
23 ******************************************************************************/
\r
25 /*! @name Driver version */
\r
27 /*! @brief LPC GPIO driver version 2.1.3. */
\r
28 #define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 1, 4))
\r
31 /*! @brief LPC GPIO direction definition */
\r
32 typedef enum _gpio_pin_direction
\r
34 kGPIO_DigitalInput = 0U, /*!< Set current pin as digital input*/
\r
35 kGPIO_DigitalOutput = 1U, /*!< Set current pin as digital output*/
\r
36 } gpio_pin_direction_t;
\r
39 * @brief The GPIO pin configuration structure.
\r
41 * Every pin can only be configured as either output pin or input pin at a time.
\r
42 * If configured as a input pin, then leave the outputConfig unused.
\r
44 typedef struct _gpio_pin_config
\r
46 gpio_pin_direction_t pinDirection; /*!< GPIO direction, input or output */
\r
47 /* Output configurations, please ignore if configured as a input one */
\r
48 uint8_t outputLogic; /*!< Set default output logic, no use in input */
\r
49 } gpio_pin_config_t;
\r
51 #if (defined(FSL_FEATURE_GPIO_HAS_INTERRUPT) && FSL_FEATURE_GPIO_HAS_INTERRUPT)
\r
52 #define GPIO_PIN_INT_LEVEL 0x00U
\r
53 #define GPIO_PIN_INT_EDGE 0x01U
\r
55 #define PINT_PIN_INT_HIGH_OR_RISE_TRIGGER 0x00U
\r
56 #define PINT_PIN_INT_LOW_OR_FALL_TRIGGER 0x01U
\r
58 /*! @brief GPIO Pin Interrupt enable mode */
\r
59 typedef enum _gpio_pin_enable_mode
\r
61 kGPIO_PinIntEnableLevel = GPIO_PIN_INT_LEVEL, /*!< Generate Pin Interrupt on level mode */
\r
62 kGPIO_PinIntEnableEdge = GPIO_PIN_INT_EDGE /*!< Generate Pin Interrupt on edge mode */
\r
63 } gpio_pin_enable_mode_t;
\r
65 /*! @brief GPIO Pin Interrupt enable polarity */
\r
66 typedef enum _gpio_pin_enable_polarity
\r
68 kGPIO_PinIntEnableHighOrRise =
\r
69 PINT_PIN_INT_HIGH_OR_RISE_TRIGGER, /*!< Generate Pin Interrupt on high level or rising edge */
\r
70 kGPIO_PinIntEnableLowOrFall =
\r
71 PINT_PIN_INT_LOW_OR_FALL_TRIGGER /*!< Generate Pin Interrupt on low level or falling edge */
\r
72 } gpio_pin_enable_polarity_t;
\r
74 /*! @brief LPC GPIO interrupt index definition */
\r
75 typedef enum _gpio_interrupt_index
\r
77 kGPIO_InterruptA = 0U, /*!< Set current pin as interrupt A*/
\r
78 kGPIO_InterruptB = 1U, /*!< Set current pin as interrupt B*/
\r
79 } gpio_interrupt_index_t;
\r
81 /*! @brief Configures the interrupt generation condition. */
\r
82 typedef struct _gpio_interrupt_config
\r
84 uint8_t mode; /* The trigger mode of GPIO interrupts */
\r
85 uint8_t polarity; /* The polarity of GPIO interrupts */
\r
86 } gpio_interrupt_config_t;
\r
89 /*******************************************************************************
\r
91 ******************************************************************************/
\r
92 #if defined(__cplusplus)
\r
97 /*! @name GPIO Configuration */
\r
101 * @brief Initializes the GPIO peripheral.
\r
103 * This function ungates the GPIO clock.
\r
105 * @param base GPIO peripheral base pointer.
\r
106 * @param port GPIO port number.
\r
108 void GPIO_PortInit(GPIO_Type *base, uint32_t port);
\r
111 * @brief Initializes a GPIO pin used by the board.
\r
113 * To initialize the GPIO, define a pin configuration, either input or output, in the user file.
\r
114 * Then, call the GPIO_PinInit() function.
\r
116 * This is an example to define an input pin or output pin configuration:
\r
118 * // Define a digital input pin configuration,
\r
119 * gpio_pin_config_t config =
\r
121 * kGPIO_DigitalInput,
\r
124 * //Define a digital output pin configuration,
\r
125 * gpio_pin_config_t config =
\r
127 * kGPIO_DigitalOutput,
\r
132 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
133 * @param port GPIO port number
\r
134 * @param pin GPIO pin number
\r
135 * @param config GPIO pin configuration pointer
\r
137 void GPIO_PinInit(GPIO_Type *base, uint32_t port, uint32_t pin, const gpio_pin_config_t *config);
\r
141 /*! @name GPIO Output Operations */
\r
145 * @brief Sets the output level of the one GPIO pin to the logic 1 or 0.
\r
147 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
148 * @param port GPIO port number
\r
149 * @param pin GPIO pin number
\r
150 * @param output GPIO pin output logic level.
\r
151 * - 0: corresponding pin output low-logic level.
\r
152 * - 1: corresponding pin output high-logic level.
\r
154 static inline void GPIO_PinWrite(GPIO_Type *base, uint32_t port, uint32_t pin, uint8_t output)
\r
156 base->B[port][pin] = output;
\r
160 /*! @name GPIO Input Operations */
\r
164 * @brief Reads the current input value of the GPIO PIN.
\r
166 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
167 * @param port GPIO port number
\r
168 * @param pin GPIO pin number
\r
169 * @retval GPIO port input value
\r
170 * - 0: corresponding pin input low-logic level.
\r
171 * - 1: corresponding pin input high-logic level.
\r
173 static inline uint32_t GPIO_PinRead(GPIO_Type *base, uint32_t port, uint32_t pin)
\r
175 return (uint32_t)base->B[port][pin];
\r
181 * @brief Sets the output level of the multiple GPIO pins to the logic 1.
\r
183 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
184 * @param port GPIO port number
\r
185 * @param mask GPIO pin number macro
\r
187 static inline void GPIO_PortSet(GPIO_Type *base, uint32_t port, uint32_t mask)
\r
189 base->SET[port] = mask;
\r
193 * @brief Sets the output level of the multiple GPIO pins to the logic 0.
\r
195 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
196 * @param port GPIO port number
\r
197 * @param mask GPIO pin number macro
\r
199 static inline void GPIO_PortClear(GPIO_Type *base, uint32_t port, uint32_t mask)
\r
201 base->CLR[port] = mask;
\r
205 * @brief Reverses current output logic of the multiple GPIO pins.
\r
207 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
208 * @param port GPIO port number
\r
209 * @param mask GPIO pin number macro
\r
211 static inline void GPIO_PortToggle(GPIO_Type *base, uint32_t port, uint32_t mask)
\r
213 base->NOT[port] = mask;
\r
219 * @brief Reads the current input value of the whole GPIO port.
\r
221 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
222 * @param port GPIO port number
\r
224 static inline uint32_t GPIO_PortRead(GPIO_Type *base, uint32_t port)
\r
226 return (uint32_t)base->PIN[port];
\r
230 /*! @name GPIO Mask Operations */
\r
234 * @brief Sets port mask, 0 - enable pin, 1 - disable pin.
\r
236 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
237 * @param port GPIO port number
\r
238 * @param mask GPIO pin number macro
\r
240 static inline void GPIO_PortMaskedSet(GPIO_Type *base, uint32_t port, uint32_t mask)
\r
242 base->MASK[port] = mask;
\r
246 * @brief Sets the output level of the masked GPIO port. Only pins enabled by GPIO_SetPortMask() will be affected.
\r
248 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
249 * @param port GPIO port number
\r
250 * @param output GPIO port output value.
\r
252 static inline void GPIO_PortMaskedWrite(GPIO_Type *base, uint32_t port, uint32_t output)
\r
254 base->MPIN[port] = output;
\r
258 * @brief Reads the current input value of the masked GPIO port. Only pins enabled by GPIO_SetPortMask() will be
\r
261 * @param base GPIO peripheral base pointer(Typically GPIO)
\r
262 * @param port GPIO port number
\r
263 * @retval masked GPIO port value
\r
265 static inline uint32_t GPIO_PortMaskedRead(GPIO_Type *base, uint32_t port)
\r
267 return (uint32_t)base->MPIN[port];
\r
270 #if defined(FSL_FEATURE_GPIO_HAS_INTERRUPT) && FSL_FEATURE_GPIO_HAS_INTERRUPT
\r
272 * @brief Configures the gpio pin interrupt.
\r
274 * @param base GPIO base pointer.
\r
275 * @param port GPIO port number
\r
276 * @param pin GPIO pin number.
\r
277 * @param config GPIO pin interrupt configuration..
\r
279 void GPIO_SetPinInterruptConfig(GPIO_Type *base, uint32_t port, uint32_t pin, gpio_interrupt_config_t *config);
\r
282 * @brief Enables multiple pins interrupt.
\r
284 * @param base GPIO base pointer.
\r
285 * @param port GPIO port number.
\r
286 * @param index GPIO interrupt number.
\r
287 * @param mask GPIO pin number macro.
\r
289 void GPIO_PortEnableInterrupts(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask);
\r
292 * @brief Disables multiple pins interrupt.
\r
294 * @param base GPIO base pointer.
\r
295 * @param port GPIO port number.
\r
296 * @param index GPIO interrupt number.
\r
297 * @param mask GPIO pin number macro.
\r
299 void GPIO_PortDisableInterrupts(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask);
\r
302 * @brief Clears pin interrupt flag. Status flags are cleared by
\r
303 * writing a 1 to the corresponding bit position.
\r
305 * @param base GPIO base pointer.
\r
306 * @param port GPIO port number.
\r
307 * @param index GPIO interrupt number.
\r
308 * @param mask GPIO pin number macro.
\r
310 void GPIO_PortClearInterruptFlags(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask);
\r
313 * @ Read port interrupt status.
\r
315 * @param base GPIO base pointer.
\r
316 * @param port GPIO port number
\r
317 * @param index GPIO interrupt number.
\r
318 * @retval masked GPIO status value
\r
320 uint32_t GPIO_PortGetInterruptStatus(GPIO_Type *base, uint32_t port, uint32_t index);
\r
323 * @brief Enables the specific pin interrupt.
\r
325 * @param base GPIO base pointer.
\r
326 * @param port GPIO port number.
\r
327 * @param pin GPIO pin number.
\r
328 * @param index GPIO interrupt number.
\r
330 void GPIO_PinEnableInterrupt(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index);
\r
333 * @brief Disables the specific pin interrupt.
\r
335 * @param base GPIO base pointer.
\r
336 * @param port GPIO port number.
\r
337 * @param pin GPIO pin number.
\r
338 * @param index GPIO interrupt number.
\r
340 void GPIO_PinDisableInterrupt(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index);
\r
343 * @brief Clears the specific pin interrupt flag. Status flags are cleared by
\r
344 * writing a 1 to the corresponding bit position.
\r
346 * @param base GPIO base pointer.
\r
347 * @param port GPIO port number.
\r
348 * @param pin GPIO pin number.
\r
349 * @param index GPIO interrupt number.
\r
351 void GPIO_PinClearInterruptFlag(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index);
\r
353 #endif /* FSL_FEATURE_GPIO_HAS_INTERRUPT */
\r
357 #if defined(__cplusplus)
\r
365 #endif /* _LPC_GPIO_H_*/
\r