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
9 #include "fsl_gpio.h"
\r
11 /* Component ID definition, used by tools. */
\r
12 #ifndef FSL_COMPONENT_ID
\r
13 #define FSL_COMPONENT_ID "platform.drivers.lpc_gpio"
\r
16 /*******************************************************************************
\r
18 ******************************************************************************/
\r
19 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
\r
20 /*! @brief Array to map FGPIO instance number to clock name. */
\r
21 static const clock_ip_name_t s_gpioClockName[] = GPIO_CLOCKS;
\r
22 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
\r
24 #if !(defined(FSL_FEATURE_GPIO_HAS_NO_RESET) && FSL_FEATURE_GPIO_HAS_NO_RESET)
\r
25 /*! @brief Pointers to GPIO resets for each instance. */
\r
26 static const reset_ip_name_t s_gpioResets[] = GPIO_RSTS_N;
\r
28 /*******************************************************************************
\r
30 ************ ******************************************************************/
\r
32 /*******************************************************************************
\r
34 ******************************************************************************/
\r
36 * brief Initializes the GPIO peripheral.
\r
38 * This function ungates the GPIO clock.
\r
40 * param base GPIO peripheral base pointer.
\r
41 * param port GPIO port number.
\r
43 void GPIO_PortInit(GPIO_Type *base, uint32_t port)
\r
45 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
\r
46 assert(port < ARRAY_SIZE(s_gpioClockName));
\r
48 /* Upgate the GPIO clock */
\r
49 CLOCK_EnableClock(s_gpioClockName[port]);
\r
50 #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
\r
51 #if !(defined(FSL_FEATURE_GPIO_HAS_NO_RESET) && FSL_FEATURE_GPIO_HAS_NO_RESET)
\r
52 /* Reset the GPIO module */
\r
53 RESET_PeripheralReset(s_gpioResets[port]);
\r
58 * brief Initializes a GPIO pin used by the board.
\r
60 * To initialize the GPIO, define a pin configuration, either input or output, in the user file.
\r
61 * Then, call the GPIO_PinInit() function.
\r
63 * This is an example to define an input pin or output pin configuration:
\r
65 * // Define a digital input pin configuration,
\r
66 * gpio_pin_config_t config =
\r
68 * kGPIO_DigitalInput,
\r
71 * //Define a digital output pin configuration,
\r
72 * gpio_pin_config_t config =
\r
74 * kGPIO_DigitalOutput,
\r
79 * param base GPIO peripheral base pointer(Typically GPIO)
\r
80 * param port GPIO port number
\r
81 * param pin GPIO pin number
\r
82 * param config GPIO pin configuration pointer
\r
84 void GPIO_PinInit(GPIO_Type *base, uint32_t port, uint32_t pin, const gpio_pin_config_t *config)
\r
86 if (config->pinDirection == kGPIO_DigitalInput)
\r
88 #if defined(FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR) && (FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR)
\r
89 base->DIRCLR[port] = 1U << pin;
\r
91 base->DIR[port] &= ~(1U << pin);
\r
92 #endif /*FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR*/
\r
96 /* Set default output value */
\r
97 if (config->outputLogic == 0U)
\r
99 base->CLR[port] = (1U << pin);
\r
103 base->SET[port] = (1U << pin);
\r
105 /* Set pin direction */
\r
106 #if defined(FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR) && (FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR)
\r
107 base->DIRSET[port] = 1U << pin;
\r
109 base->DIR[port] |= 1U << pin;
\r
110 #endif /*FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR*/
\r