Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:59

0001 /*
0002  * Copyright (c) 2016, Freescale Semiconductor, Inc.
0003  * Copyright 2016-2020 NXP
0004  * All rights reserved.
0005  *
0006  * SPDX-License-Identifier: BSD-3-Clause
0007  */
0008 
0009 #ifndef _FSL_GPIO_H_
0010 #define _FSL_GPIO_H_
0011 
0012 #include "fsl_common.h"
0013 
0014 /*!
0015  * @addtogroup gpio_driver
0016  * @{
0017  */
0018 
0019 /*******************************************************************************
0020  * Definitions
0021  ******************************************************************************/
0022 
0023 /*! @name Driver version */
0024 /*@{*/
0025 /*! @brief GPIO driver version. */
0026 #define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 6))
0027 /*@}*/
0028 
0029 /*! @brief GPIO direction definition. */
0030 typedef enum _gpio_pin_direction
0031 {
0032     kGPIO_DigitalInput  = 0U, /*!< Set current pin as digital input.*/
0033     kGPIO_DigitalOutput = 1U, /*!< Set current pin as digital output.*/
0034 } gpio_pin_direction_t;
0035 
0036 /*! @brief GPIO interrupt mode definition. */
0037 typedef enum _gpio_interrupt_mode
0038 {
0039     kGPIO_NoIntmode              = 0U, /*!< Set current pin general IO functionality.*/
0040     kGPIO_IntLowLevel            = 1U, /*!< Set current pin interrupt is low-level sensitive.*/
0041     kGPIO_IntHighLevel           = 2U, /*!< Set current pin interrupt is high-level sensitive.*/
0042     kGPIO_IntRisingEdge          = 3U, /*!< Set current pin interrupt is rising-edge sensitive.*/
0043     kGPIO_IntFallingEdge         = 4U, /*!< Set current pin interrupt is falling-edge sensitive.*/
0044     kGPIO_IntRisingOrFallingEdge = 5U, /*!< Enable the edge select bit to override the ICR register's configuration.*/
0045 } gpio_interrupt_mode_t;
0046 
0047 /*! @brief GPIO Init structure definition. */
0048 typedef struct _gpio_pin_config
0049 {
0050     gpio_pin_direction_t direction; /*!< Specifies the pin direction. */
0051     uint8_t outputLogic;            /*!< Set a default output logic, which has no use in input */
0052     gpio_interrupt_mode_t
0053         interruptMode; /*!< Specifies the pin interrupt mode, a value of @ref gpio_interrupt_mode_t. */
0054 } gpio_pin_config_t;
0055 
0056 /*******************************************************************************
0057  * API
0058  ******************************************************************************/
0059 
0060 #if defined(__cplusplus)
0061 extern "C" {
0062 #endif
0063 
0064 /*!
0065  * @name GPIO Initialization and Configuration functions
0066  * @{
0067  */
0068 
0069 /*!
0070  * @brief Initializes the GPIO peripheral according to the specified
0071  *        parameters in the initConfig.
0072  *
0073  * @param base GPIO base pointer.
0074  * @param pin Specifies the pin number
0075  * @param Config pointer to a @ref gpio_pin_config_t structure that
0076  *        contains the configuration information.
0077  */
0078 void GPIO_PinInit(GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *Config);
0079 /*@}*/
0080 
0081 /*!
0082  * @name GPIO Reads and Write Functions
0083  * @{
0084  */
0085 
0086 /*!
0087  * @brief Sets the output level of the individual GPIO pin to logic 1 or 0.
0088  *
0089  * @param base GPIO base pointer.
0090  * @param pin GPIO port pin number.
0091  * @param output GPIOpin output logic level.
0092  *        - 0: corresponding pin output low-logic level.
0093  *        - 1: corresponding pin output high-logic level.
0094  */
0095 void GPIO_PinWrite(GPIO_Type *base, uint32_t pin, uint8_t output);
0096 
0097 /*!
0098  * @brief Sets the output level of the individual GPIO pin to logic 1 or 0.
0099  * @deprecated Do not use this function.  It has been superceded by @ref GPIO_PinWrite.
0100  */
0101 static inline void GPIO_WritePinOutput(GPIO_Type *base, uint32_t pin, uint8_t output)
0102 {
0103     GPIO_PinWrite(base, pin, output);
0104 }
0105 
0106 /*!
0107  * @brief Sets the output level of the multiple GPIO pins to the logic 1.
0108  *
0109  * @param base GPIO peripheral base pointer (GPIO1, GPIO2, GPIO3, and so on.)
0110  * @param mask GPIO pin number macro
0111  */
0112 static inline void GPIO_PortSet(GPIO_Type *base, uint32_t mask)
0113 {
0114 #if (defined(FSL_FEATURE_IGPIO_HAS_DR_SET) && (FSL_FEATURE_IGPIO_HAS_DR_SET == 1))
0115     base->DR_SET = mask;
0116 #else
0117     base->DR |= mask;
0118 #endif /* FSL_FEATURE_IGPIO_HAS_DR_SET */
0119 }
0120 
0121 /*!
0122  * @brief Sets the output level of the multiple GPIO pins to the logic 1.
0123  * @deprecated Do not use this function.  It has been superceded by @ref GPIO_PortSet.
0124  */
0125 static inline void GPIO_SetPinsOutput(GPIO_Type *base, uint32_t mask)
0126 {
0127     GPIO_PortSet(base, mask);
0128 }
0129 
0130 /*!
0131  * @brief Sets the output level of the multiple GPIO pins to the logic 0.
0132  *
0133  * @param base GPIO peripheral base pointer (GPIO1, GPIO2, GPIO3, and so on.)
0134  * @param mask GPIO pin number macro
0135  */
0136 static inline void GPIO_PortClear(GPIO_Type *base, uint32_t mask)
0137 {
0138 #if (defined(FSL_FEATURE_IGPIO_HAS_DR_CLEAR) && (FSL_FEATURE_IGPIO_HAS_DR_CLEAR == 1))
0139     base->DR_CLEAR = mask;
0140 #else
0141     base->DR &= ~mask;
0142 #endif /* FSL_FEATURE_IGPIO_HAS_DR_CLEAR */
0143 }
0144 
0145 /*!
0146  * @brief Sets the output level of the multiple GPIO pins to the logic 0.
0147  * @deprecated Do not use this function.  It has been superceded by @ref GPIO_PortClear.
0148  */
0149 static inline void GPIO_ClearPinsOutput(GPIO_Type *base, uint32_t mask)
0150 {
0151     GPIO_PortClear(base, mask);
0152 }
0153 
0154 /*!
0155  * @brief Reverses the current output logic of the multiple GPIO pins.
0156  *
0157  * @param base GPIO peripheral base pointer (GPIO1, GPIO2, GPIO3, and so on.)
0158  * @param mask GPIO pin number macro
0159  */
0160 static inline void GPIO_PortToggle(GPIO_Type *base, uint32_t mask)
0161 {
0162 #if (defined(FSL_FEATURE_IGPIO_HAS_DR_TOGGLE) && (FSL_FEATURE_IGPIO_HAS_DR_TOGGLE == 1))
0163     base->DR_TOGGLE = mask;
0164 #else
0165     base->DR ^= mask;
0166 #endif /* FSL_FEATURE_IGPIO_HAS_DR_TOGGLE */
0167 }
0168 
0169 /*!
0170  * @brief Reads the current input value of the GPIO port.
0171  *
0172  * @param base GPIO base pointer.
0173  * @param pin GPIO port pin number.
0174  * @retval GPIO port input value.
0175  */
0176 static inline uint32_t GPIO_PinRead(GPIO_Type *base, uint32_t pin)
0177 {
0178     assert(pin < 32U);
0179 
0180     return (((base->DR) >> pin) & 0x1U);
0181 }
0182 
0183 /*!
0184  * @brief Reads the current input value of the GPIO port.
0185  * @deprecated Do not use this function.  It has been superceded by @ref GPIO_PinRead.
0186  */
0187 static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t pin)
0188 {
0189     return GPIO_PinRead(base, pin);
0190 }
0191 /*@}*/
0192 
0193 /*!
0194  * @name GPIO Reads Pad Status Functions
0195  * @{
0196  */
0197 
0198 /*!
0199  * @brief Reads the current GPIO pin pad status.
0200  *
0201  * @param base GPIO base pointer.
0202  * @param pin GPIO port pin number.
0203  * @retval GPIO pin pad status value.
0204  */
0205 static inline uint8_t GPIO_PinReadPadStatus(GPIO_Type *base, uint32_t pin)
0206 {
0207     assert(pin < 32U);
0208 
0209     return (uint8_t)(((base->PSR) >> pin) & 0x1U);
0210 }
0211 
0212 /*!
0213  * @brief Reads the current GPIO pin pad status.
0214  * @deprecated Do not use this function.  It has been superceded by @ref GPIO_PinReadPadStatus.
0215  */
0216 static inline uint8_t GPIO_ReadPadStatus(GPIO_Type *base, uint32_t pin)
0217 {
0218     return GPIO_PinReadPadStatus(base, pin);
0219 }
0220 
0221 /*@}*/
0222 
0223 /*!
0224  * @name Interrupts and flags management functions
0225  * @{
0226  */
0227 
0228 /*!
0229  * @brief Sets the current pin interrupt mode.
0230  *
0231  * @param base GPIO base pointer.
0232  * @param pin GPIO port pin number.
0233  * @param pinInterruptMode pointer to a @ref gpio_interrupt_mode_t structure
0234  *        that contains the interrupt mode information.
0235  */
0236 void GPIO_PinSetInterruptConfig(GPIO_Type *base, uint32_t pin, gpio_interrupt_mode_t pinInterruptMode);
0237 
0238 /*!
0239  * @brief Sets the current pin interrupt mode.
0240  * @deprecated Do not use this function.  It has been superceded by @ref GPIO_PinSetInterruptConfig.
0241  */
0242 static inline void GPIO_SetPinInterruptConfig(GPIO_Type *base, uint32_t pin, gpio_interrupt_mode_t pinInterruptMode)
0243 {
0244     GPIO_PinSetInterruptConfig(base, pin, pinInterruptMode);
0245 }
0246 
0247 /*!
0248  * @brief Enables the specific pin interrupt.
0249  *
0250  * @param base GPIO base pointer.
0251  * @param mask GPIO pin number macro.
0252  */
0253 static inline void GPIO_PortEnableInterrupts(GPIO_Type *base, uint32_t mask)
0254 {
0255     base->IMR |= mask;
0256 }
0257 
0258 /*!
0259  * @brief Enables the specific pin interrupt.
0260  *
0261  * @param base GPIO base pointer.
0262  * @param mask GPIO pin number macro.
0263  */
0264 static inline void GPIO_EnableInterrupts(GPIO_Type *base, uint32_t mask)
0265 {
0266     GPIO_PortEnableInterrupts(base, mask);
0267 }
0268 
0269 /*!
0270  * @brief Disables the specific pin interrupt.
0271  *
0272  * @param base GPIO base pointer.
0273  * @param mask GPIO pin number macro.
0274  */
0275 static inline void GPIO_PortDisableInterrupts(GPIO_Type *base, uint32_t mask)
0276 {
0277     base->IMR &= ~mask;
0278 }
0279 
0280 /*!
0281  * @brief Disables the specific pin interrupt.
0282  * @deprecated Do not use this function.  It has been superceded by @ref GPIO_PortDisableInterrupts.
0283  */
0284 static inline void GPIO_DisableInterrupts(GPIO_Type *base, uint32_t mask)
0285 {
0286     GPIO_PortDisableInterrupts(base, mask);
0287 }
0288 
0289 /*!
0290  * @brief Reads individual pin interrupt status.
0291  *
0292  * @param base GPIO base pointer.
0293  * @retval current pin interrupt status flag.
0294  */
0295 static inline uint32_t GPIO_PortGetInterruptFlags(GPIO_Type *base)
0296 {
0297     return base->ISR;
0298 }
0299 
0300 /*!
0301  * @brief Reads individual pin interrupt status.
0302  *
0303  * @param base GPIO base pointer.
0304  * @retval current pin interrupt status flag.
0305  */
0306 static inline uint32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base)
0307 {
0308     return GPIO_PortGetInterruptFlags(base);
0309 }
0310 
0311 /*!
0312  * @brief Clears pin interrupt flag. Status flags are cleared by
0313  *        writing a 1 to the corresponding bit position.
0314  *
0315  * @param base GPIO base pointer.
0316  * @param mask GPIO pin number macro.
0317  */
0318 static inline void GPIO_PortClearInterruptFlags(GPIO_Type *base, uint32_t mask)
0319 {
0320     base->ISR = mask;
0321 }
0322 
0323 /*!
0324  * @brief Clears pin interrupt flag. Status flags are cleared by
0325  *        writing a 1 to the corresponding bit position.
0326  *
0327  * @param base GPIO base pointer.
0328  * @param mask GPIO pin number macro.
0329  */
0330 static inline void GPIO_ClearPinsInterruptFlags(GPIO_Type *base, uint32_t mask)
0331 {
0332     GPIO_PortClearInterruptFlags(base, mask);
0333 }
0334 /*@}*/
0335 
0336 #if defined(__cplusplus)
0337 }
0338 #endif
0339 
0340 /*!
0341  * @}
0342  */
0343 
0344 #endif /* _FSL_GPIO_H_*/