Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
fsl_gpio.h
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SDRVL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _FSL_GPIO_H_
32 #define _FSL_GPIO_H_
33 
34 #include "fsl_common.h"
35 
41 /*******************************************************************************
42  * Definitions
43  ******************************************************************************/
45 #define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
48 typedef enum _gpio_pin_direction
49 {
53 
62 typedef struct _gpio_pin_config
63 {
65  /* Output configurations, please ignore if configured as a input one */
66  uint8_t outputLogic;
68 /*******************************************************************************
69  * API
70  ******************************************************************************/
71 
72 #if defined(__cplusplus)
73 extern "C" {
74 #endif
75 
107 void GPIO_PinInit(GPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config);
108 /* @} */
109 
124 static inline void GPIO_WritePinOutput(GPIO_Type *base, uint32_t pin, uint8_t output)
125 {
126  if (output == 0U)
127  {
128  base->PCOR = 1 << pin;
129  }
130  else
131  {
132  base->PSOR = 1 << pin;
133  }
134 }
135 
142 static inline void GPIO_SetPinsOutput(GPIO_Type *base, uint32_t mask)
143 {
144  base->PSOR = mask;
145 }
152 static inline void GPIO_ClearPinsOutput(GPIO_Type *base, uint32_t mask)
153 {
154  base->PCOR = mask;
155 }
162 static inline void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t mask)
163 {
164  base->PTOR = mask;
165 }
166 /* @} */
167 
182 static inline uint32_t GPIO_ReadPinInput(GPIO_Type *base, uint32_t pin)
183 {
184  return (((base->PDIR) >> pin) & 0x01U);
185 }
186 /* @} */
187 
206 uint32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base);
207 
214 void GPIO_ClearPinsInterruptFlags(GPIO_Type *base, uint32_t mask);
215 
216 /* @} */
217 
227 #if defined(FSL_FEATURE_SOC_FGPIO_COUNT) && FSL_FEATURE_SOC_FGPIO_COUNT
228 
268 void FGPIO_PinInit(FGPIO_Type *base, uint32_t pin, const gpio_pin_config_t *config);
269 
270 /* @} */
271 
286 static inline void FGPIO_WritePinOutput(FGPIO_Type *base, uint32_t pin, uint8_t output)
287 {
288  if (output == 0U)
289  {
290  base->PCOR = 1 << pin;
291  }
292  else
293  {
294  base->PSOR = 1 << pin;
295  }
296 }
297 
304 static inline void FGPIO_SetPinsOutput(FGPIO_Type *base, uint32_t mask)
305 {
306  base->PSOR = mask;
307 }
314 static inline void FGPIO_ClearPinsOutput(FGPIO_Type *base, uint32_t mask)
315 {
316  base->PCOR = mask;
317 }
324 static inline void FGPIO_TogglePinsOutput(FGPIO_Type *base, uint32_t mask)
325 {
326  base->PTOR = mask;
327 }
328 /* @} */
329 
344 static inline uint32_t FGPIO_ReadPinInput(FGPIO_Type *base, uint32_t pin)
345 {
346  return (((base->PDIR) >> pin) & 0x01U);
347 }
348 /* @} */
349 
368 uint32_t FGPIO_GetPinsInterruptFlags(FGPIO_Type *base);
369 
376 void FGPIO_ClearPinsInterruptFlags(FGPIO_Type *base, uint32_t mask);
377 
378 /* @} */
379 
380 #endif /* FSL_FEATURE_SOC_FGPIO_COUNT */
381 
382 /* @} */
383 
384 #if defined(__cplusplus)
385 }
386 #endif
387 
392 #endif /* _FSL_GPIO_H_*/
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 direction definition.
Definition: fsl_gpio.h:48
static void FGPIO_TogglePinsOutput(FGPIO_Type *base, uint32_t mask)
Reverses current output logic of the multiple FGPIO pins.
Definition: fsl_gpio.h:324
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
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
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
uint32_t GPIO_GetPinsInterruptFlags(GPIO_Type *base)
Reads whole GPIO port interrupt status flag.
Definition: fsl_gpio.c:88
gpio_pin_direction_t pinDirection
Definition: fsl_gpio.h:64
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
Definition: fsl_gpio.h:50
void FGPIO_ClearPinsInterruptFlags(FGPIO_Type *base, uint32_t mask)
Clears the multiple FGPIO pins&#39; interrupt status flag.
Definition: fsl_gpio.c:170
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
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
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
Definition: fsl_gpio.h:51
uint8_t outputLogic
Definition: fsl_gpio.h:66
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
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
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
static void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t mask)
Reverses current output logic of the multiple GPIO pins.
Definition: fsl_gpio.h:162
uint32_t FGPIO_GetPinsInterruptFlags(FGPIO_Type *base)
Reads the whole FGPIO port interrupt status flag.
Definition: fsl_gpio.c:161
The GPIO pin configuration structure.
Definition: fsl_gpio.h:62