1 /*
2 * Copyright 2017 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 /**
9 * @file gpio_driver.c
10 * @brief The gpio_driver.c file contains Generic API Adaption to i.MXRT1050 SDK 2.0 GPIO Driver.
11 */
12
13 #include "gpio_driver.h"
14
15 /*******************************************************************************
16 * Definitions
17 ******************************************************************************/
18 #define GPIO_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(2, 3) /* driver version */
19 // ISR handler array for each gpio pin in the system
20 #define GPIO_NUMBER_OF_PIN 0x20
21
22 /*******************************************************************************
23 * Variables
24 ******************************************************************************/
25
26 /* Driver Version */
27 static const GENERIC_DRIVER_VERSION DriverVersion = {GPIO_API_VERSION, GPIO_DRV_VERSION};
28 //static gpioIsrObj_t isrObj[TOTAL_NUMBER_PORT][GPIO_NUMBER_OF_PIN];
29 static gpioConfigiMXSDK_t gpioConfigDefault = {
30 .pinConfig = {kGPIO_DigitalInput, 0},
31 .interruptMode = {kGPIO_PinIntEnableEdge, kGPIO_PinIntEnableLowOrFall}
32 };
33
34 /*******************************************************************************
35 * Code
36 ******************************************************************************/
37
38 /***********************************************************************
39 *
40 * Function Name : imxsdk_gpio_get_version
41 * Description : get the i.MXRT1050RT gpio driver version.
42 *
43 ***************************************************************************/
imxsdk_gpio_get_version(void)44 GENERIC_DRIVER_VERSION imxsdk_gpio_get_version(void)
45 {
46 return DriverVersion;
47 }
48
49 /***********************************************************************
50 *
51 * Function Name : imxsdk_gpio_pin_init
52 * Description : Initialize particular GPIO pin used by board.
53 *
54 ***************************************************************************/
imxsdk_gpio_pin_init(pinID_t aPinId,gpio_direction_t dir,void * apPinConfig,gpio_isr_handler_t aIsrHandler,void * apUserData)55 void imxsdk_gpio_pin_init(
56 pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
57 {
58 gpioConfigiMXSDK_t *pGpioConfig = (gpioConfigiMXSDK_t *)apPinConfig;
59 gpioHandleiMXSDK_t *pinHandle = (gpioHandleiMXSDK_t *)aPinId;
60 if (NULL == apPinConfig)
61 {
62 pGpioConfig = &gpioConfigDefault;
63 }
64
65 pGpioConfig->pinConfig.pinDirection = dir == GPIO_DIRECTION_IN ? kGPIO_DigitalInput : kGPIO_DigitalOutput;
66 /* Set the pin information */
67 GPIO_PinInit(pinHandle->base, pinHandle->portNumber, pinHandle->pinNumber, &pGpioConfig->pinConfig);
68
69 /* Isr is installed */
70 // if (aIsrHandler)
71 // {
72 // /* Enable the IRQ */
73 // EnableIRQ(pinHandle->irq);
74 // isrObj[pinHandle->portNumber][pinHandle->pinNumber].isrHandle = aIsrHandler;
75 // isrObj[pinHandle->portNumber][pinHandle->pinNumber].pUserData = apUserData;
76 // /* Enable GPIO pin interrupt */
77 // GPIO_PortEnableInterrupts(pinHandle->base, pinHandle->portNumber, pinHandle->irq, pinHandle->mask);
78 // }
79 }
80
81 /***********************************************************************
82 *
83 * Function Name : imxsdk_gpio_set_pin
84 * Description : Set output level of individual GPIO pin to logic 1.
85 *
86 ***************************************************************************/
imxsdk_gpio_set_pin(pinID_t aPinId)87 void imxsdk_gpio_set_pin(pinID_t aPinId)
88 {
89 gpioHandleiMXSDK_t *pinHandle = (gpioHandleiMXSDK_t *)aPinId;
90 pinHandle->pinStatus = PIN_SET;
91 GPIO_PinWrite(pinHandle->base, pinHandle->portNumber, pinHandle->pinNumber, PIN_SET);
92 }
93
94 /***********************************************************************
95 *
96 * Function Name : imxsdk_gpio_clr_pin
97 * Description : Set output level of individual GPIO pin to logic 0..
98 *
99 ***************************************************************************/
imxsdk_gpio_clr_pin(pinID_t aPinId)100 void imxsdk_gpio_clr_pin(pinID_t aPinId)
101 {
102 gpioHandleiMXSDK_t *pinHandle = (gpioHandleiMXSDK_t *)aPinId;
103 pinHandle->pinStatus = PIN_CLR;
104 GPIO_PinWrite(pinHandle->base, pinHandle->portNumber, pinHandle->pinNumber, PIN_CLR);
105 }
106
107 /***********************************************************************
108 *
109 * Function Name : ksdk_gpio_toggle_pin
110 * Description : toggle the currrent output logic of individual GPIO pin.
111 *
112 ***************************************************************************/
imxsdk_gpio_toggle_pin(pinID_t aPinId)113 void imxsdk_gpio_toggle_pin(pinID_t aPinId)
114 {
115 gpioHandleiMXSDK_t *pinHandle = (gpioHandleiMXSDK_t *)aPinId;
116
117 /* Check PIN Status and toggle */
118 if (PIN_CLR == pinHandle->pinStatus)
119 {
120 imxsdk_gpio_set_pin(aPinId);
121 }
122 else if (PIN_SET == pinHandle->pinStatus)
123 {
124 imxsdk_gpio_clr_pin(aPinId);
125 }
126 }
127
128 GENERIC_DRIVER_GPIO Driver_GPIO_KSDK = {
129 imxsdk_gpio_get_version, imxsdk_gpio_pin_init, imxsdk_gpio_set_pin,
130 imxsdk_gpio_clr_pin, imxsdk_gpio_toggle_pin
131 };
132