fsl_gpio.h
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SDRVL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FSL_GPIO_H_
#define _FSL_GPIO_H_
#include "fsl_common.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
typedef enum _gpio_pin_direction
{
kGPIO_DigitalInput = 0U,
kGPIO_DigitalOutput = 1U,
} gpio_pin_direction_t;
typedef struct _gpio_pin_config
{
gpio_pin_direction_t pinDirection;
/* Output configurations, please ignore if configured as a input one */
uint8_t outputLogic;
} gpio_pin_config_t;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
void GPIO_PinInit(GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config);
/* @} */
static inline void GPIO_WritePinOutput(GPIO_Type *base, uint32_t pin, uint8_t output)
{
if (output == 0U)
{
base->PCOR = 1 << pin;
}
else
{
base->PSOR = 1 << pin;
}
}
static inline void GPIO_SetPinsOutput(GPIO_Type *base, uint32_t mask)
{
base->PSOR = mask;
}
static inline void GPIO_ClearPinsOutput(GPIO_Type *base, uint32_t mask)
{
base->PCOR = mask;
}
static inline void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t mask)
{
base->PTOR = mask;
}
/* @} */
static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t pin)
{
return (((base->PDIR) >> pin) & 0x01U);
}
/* @} */
uint32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base);
void GPIO_ClearPinsInterruptFlags(GPIO_Type *base, uint32_t mask);
/* @} */
#if defined(FSL_FEATURE_SOC_FGPIO_COUNT) && FSL_FEATURE_SOC_FGPIO_COUNT
void FGPIO_PinInit(FGPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config);
/* @} */
static inline void FGPIO_WritePinOutput(FGPIO_Type *base, uint32_t pin, uint8_t output)
{
if (output == 0U)
{
base->PCOR = 1 << pin;
}
else
{
base->PSOR = 1 << pin;
}
}
static inline void FGPIO_SetPinsOutput(FGPIO_Type *base, uint32_t mask)
{
base->PSOR = mask;
}
static inline void FGPIO_ClearPinsOutput(FGPIO_Type *base, uint32_t mask)
{
base->PCOR = mask;
}
static inline void FGPIO_TogglePinsOutput(FGPIO_Type *base, uint32_t mask)
{
base->PTOR = mask;
}
/* @} */
static inline uint32_t FGPIO_ReadPinInput(FGPIO_Type *base, uint32_t pin)
{
return (((base->PDIR) >> pin) & 0x01U);
}
/* @} */
uint32_t FGPIO_GetPinsInterruptFlags(FGPIO_Type *base);
void FGPIO_ClearPinsInterruptFlags(FGPIO_Type *base, uint32_t mask);
/* @} */
#endif /* FSL_FEATURE_SOC_FGPIO_COUNT */
/* @} */
#if defined(__cplusplus)
}
#endif
#endif /* _FSL_GPIO_H_*/
GPIO_ClearPinsInterruptFlags
void GPIO_ClearPinsInterruptFlags(GPIO_Type *base, uint32_t mask)
Clears multiple GPIO pins&#39; interrupt status flag.
Definition: fsl_gpio.c:97
gpio_pin_direction_t
gpio_pin_direction_t
GPIO direction definition.
Definition: fsl_gpio.h:48
FGPIO_TogglePinsOutput
static void FGPIO_TogglePinsOutput(FGPIO_Type *base, uint32_t mask)
Reverses current output logic of the multiple FGPIO pins.
Definition: fsl_gpio.h:324
FGPIO_ClearPinsOutput
static void FGPIO_ClearPinsOutput(FGPIO_Type *base, uint32_t mask)
Sets the output level of the multiple FGPIO pins to the logic 0.
Definition: fsl_gpio.h:314
FGPIO_ReadPinInput
static uint32_t FGPIO_ReadPinInput(FGPIO_Type *base, uint32_t pin)
Reads the current input value of the whole FGPIO port.
Definition: fsl_gpio.h:344
FGPIO_SetPinsOutput
static void FGPIO_SetPinsOutput(FGPIO_Type *base, uint32_t mask)
Sets the output level of the multiple FGPIO pins to the logic 1.
Definition: fsl_gpio.h:304
GPIO_GetPinsInterruptFlags
uint32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base)
Reads whole GPIO port interrupt status flag.
Definition: fsl_gpio.c:88
gpio_pin_config_t::pinDirection
gpio_pin_direction_t pinDirection
Definition: fsl_gpio.h:64
FGPIO_WritePinOutput
static void FGPIO_WritePinOutput(FGPIO_Type *base, uint32_t pin, uint8_t output)
Sets the output level of the multiple FGPIO pins to the logic 1 or 0.
Definition: fsl_gpio.h:286
kGPIO_DigitalInput
Definition: fsl_gpio.h:50
FGPIO_ClearPinsInterruptFlags
void FGPIO_ClearPinsInterruptFlags(FGPIO_Type *base, uint32_t mask)
Clears the multiple FGPIO pins&#39; interrupt status flag.
Definition: fsl_gpio.c:170
GPIO_WritePinOutput
static void GPIO_WritePinOutput(GPIO_Type *base, uint32_t pin, uint8_t output)
Sets the output level of the multiple GPIO pins to the logic 1 or 0.
Definition: fsl_gpio.h:124
GPIO_PinInit
void GPIO_PinInit(GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config)
Initializes a GPIO pin used by the board.
Definition: fsl_gpio.c:73
GPIO_ReadPinInput
static uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t pin)
Reads the current input value of the whole GPIO port.
Definition: fsl_gpio.h:182
kGPIO_DigitalOutput
Definition: fsl_gpio.h:51
gpio_pin_config_t::outputLogic
uint8_t outputLogic
Definition: fsl_gpio.h:66
FGPIO_PinInit
void FGPIO_PinInit(FGPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config)
Initializes a FGPIO pin used by the board.
Definition: fsl_gpio.c:146
GPIO_ClearPinsOutput
static void GPIO_ClearPinsOutput(GPIO_Type *base, uint32_t mask)
Sets the output level of the multiple GPIO pins to the logic 0.
Definition: fsl_gpio.h:152
GPIO_SetPinsOutput
static void GPIO_SetPinsOutput(GPIO_Type *base, uint32_t mask)
Sets the output level of the multiple GPIO pins to the logic 1.
Definition: fsl_gpio.h:142
GPIO_TogglePinsOutput
static void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t mask)
Reverses current output logic of the multiple GPIO pins.
Definition: fsl_gpio.h:162
FGPIO_GetPinsInterruptFlags
uint32_t FGPIO_GetPinsInterruptFlags(FGPIO_Type *base)
Reads the whole FGPIO port interrupt status flag.
Definition: fsl_gpio.c:161
gpio_pin_config_t
The GPIO pin configuration structure.
Definition: fsl_gpio.h:62