1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file gpio_driver.h
11  * @brief The gpio_driver.h file containes the Generic Irq implmentation for the gpio.
12  *        The type and variable names have been kept aligned to Kinetis family for compatibility of examples.
13 */
14 
15 #ifndef __DRIVER_GPIO_H__
16 #define __DRIVER_GPIO_H__
17 
18 #include "Driver_Common.h"
19 #include "Driver_GPIO.h"
20 #include "fsl_common.h"
21 #include "fsl_gpio.h"
22 #include "fsl_gint.h"
23 
24 typedef enum _gint_interrupt
25 {
26     kGINT_InterruptLogic_0 = 0x0U, /*!< Interrupt on Logic 0 (Falling Edge or Level Low). */
27     kGINT_InterruptLogic_1 = 0x1U, /*!< Interrupt on Logic 1 (Rising Edge or Level High). */
28 } gint_interrupt_t;
29 
30 /*!
31  * @brief The GPIO Configuration KSDK.
32  */
33 typedef struct gpioConfigKSDK
34 {
35     gpio_pin_config_t pinConfig;         /*!< General pin charactertics.*/
36     gint_trig_t       interruptMode;     /*!< Interrupt mode for a pin.*/
37     gint_interrupt_t  interruptPolarity; /*!< Interrupt Polarity 0/1 for a pin.*/
38 } gpioConfigKSDK_t;
39 
40 /*!
41  * @brief The GPIO pin handle for KSDK.
42  */
43 typedef struct gpioHandleKSDK
44 {
45     GPIO_Type *base;           /*!< Base address of the GPIO Port.*/
46     uint32_t pinNumber;        /*!< pin number start from 0 -31.*/
47     uint32_t mask;             /*!< mask value for a pin.*/
48     clock_ip_name_t clockName; /*!< Clock Name for the port.*/
49     gint_port_t portNumber;    /*!< Port Number for the port.*/
50 } gpioHandleKSDK_t;
51 
52 /*!
53  * @brief The gpio isr object.
54  */
55 typedef struct gpioIsrObj
56 {
57     void *pUserData;              /*!< Pointer to a UserData.*/
58     gpio_isr_handler_t isrHandle; /*!< pointer to isrHandle.*/
59 } gpioIsrObj_t;
60 
61 /*!
62  * @brief Macro to create a Gpio handle
63  */
64 #define MAKE_GPIO_HANDLE(PortName, Base, PinNumber, ClockName, PortNumber)   \
65     static gpioHandleKSDK_t PortName##PinNumber = {.base = Base,             \
66                                                    .pinNumber = PinNumber,   \
67                                                    .mask = 1 << (PinNumber), \
68                                                    .clockName = ClockName,   \
69                                                    .portNumber = PortNumber};
70 
71 #define GPIO_PIN_ID(PortName, PinNumber) &(PortName##PinNumber)
72 extern GENERIC_DRIVER_GPIO Driver_GPIO_KSDK;
73 
74 #endif // __DRIVER_GPIO_H__
75