ADuCM302x Device Drivers API Reference Manual  Release 3.1.2.0
adi_gpio.h
1 /*
2  *****************************************************************************
3  @file: adi_gpio.h
4  @brief: GPIO definitions and API
5  -----------------------------------------------------------------------------
6 
7 Copyright (c) 2016-2018 Analog Devices, Inc.
8 
9 All rights reserved.
10 
11 Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
13  - Redistributions of source code must retain the above copyright notice,
14  this list of conditions and the following disclaimer.
15  - Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18  - Modified versions of the software must be conspicuously marked as such.
19  - This software is licensed solely and exclusively for use with processors
20  manufactured by or for Analog Devices, Inc.
21  - This software may not be combined or merged with other code in any manner
22  that would cause the software to become subject to terms and conditions
23  which differ from those listed here.
24  - Neither the name of Analog Devices, Inc. nor the names of its
25  contributors may be used to endorse or promote products derived
26  from this software without specific prior written permission.
27  - The use of this software may or may not infringe the patent rights of one
28  or more patent holders. This license does not release you from the
29  requirement that you obtain separate licenses from these patent holders
30  to use this software.
31 
32 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY
33 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
34 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
35 NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
36 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
37 (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
38 PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
39 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 
44 *****************************************************************************/
45 #ifndef ADI_GPIO_H
46 #define ADI_GPIO_H
47 
48 #include <adi_processor.h>
49 #include <adi_callback.h>
50 
51 #ifdef __ICCARM__
52 /* IAR MISRA C 2004 error suppressions.
53  *
54  * Pm008 (rule 2.4): sections of code should not be 'commented out'.
55  * Allow code example in doxygen comment.
56  * Pm011 (rule 6.3): The basic types of char, int, long, float cannot be used.
57  * bool is used in the APIs as it is not affending the rule. Disabling this as IAR treats it as an error.
58  */
59 #pragma diag_suppress=Pm008,Pm011
60 #endif /* __ICCARM__ */
61 
66 #ifdef __ICCARM__
67 #pragma diag_default=Pm008
68 #endif /* __ICCARM__ */
69 
70 /* C++ linkage */
71 #ifdef __cplusplus
72 extern "C" {
73 #endif /* __cplusplus */
74 
78 #define ADI_GPIO_MEMORY_SIZE (16u)
79 
80 /* typedefs for 16-bit Ports */
81 typedef uint16_t ADI_GPIO_DATA;
85 typedef enum
86 {
99 
100 
102 typedef enum {
109 
111 typedef enum {
112  ADI_GPIO_INTA_IRQ = SYS_GPIO_INTA_IRQn,
113  ADI_GPIO_INTB_IRQ = SYS_GPIO_INTB_IRQn,
114 } ADI_GPIO_IRQ;
115 
116 
118 typedef enum {
122 #if defined(__ADUCM4x50__)
123  ADI_GPIO_PORT3,
124 #endif /* __ADUCM4x50__ */
126 } ADI_GPIO_PORT;
127 
128 /* 16-bit port pin defs */
129 #define ADI_GPIO_PIN_0 ((ADI_GPIO_DATA)(0x0001))
130 #define ADI_GPIO_PIN_1 ((ADI_GPIO_DATA)(0x0002))
131 #define ADI_GPIO_PIN_2 ((ADI_GPIO_DATA)(0x0004))
132 #define ADI_GPIO_PIN_3 ((ADI_GPIO_DATA)(0x0008))
133 #define ADI_GPIO_PIN_4 ((ADI_GPIO_DATA)(0x0010))
134 #define ADI_GPIO_PIN_5 ((ADI_GPIO_DATA)(0x0020))
135 #define ADI_GPIO_PIN_6 ((ADI_GPIO_DATA)(0x0040))
136 #define ADI_GPIO_PIN_7 ((ADI_GPIO_DATA)(0x0080))
137 #define ADI_GPIO_PIN_8 ((ADI_GPIO_DATA)(0x0100))
138 #define ADI_GPIO_PIN_9 ((ADI_GPIO_DATA)(0x0200))
139 #define ADI_GPIO_PIN_10 ((ADI_GPIO_DATA)(0x0400))
140 #define ADI_GPIO_PIN_11 ((ADI_GPIO_DATA)(0x0800))
141 #define ADI_GPIO_PIN_12 ((ADI_GPIO_DATA)(0x1000))
142 #define ADI_GPIO_PIN_13 ((ADI_GPIO_DATA)(0x2000))
143 #define ADI_GPIO_PIN_14 ((ADI_GPIO_DATA)(0x4000))
144 #define ADI_GPIO_PIN_15 ((ADI_GPIO_DATA)(0x8000))
146 /* GPIO port pins availability mask */
147 #define ADI_GPIO_PORT0_PIN_AVL (0xFFFFu)
148 #define ADI_GPIO_PORT1_PIN_AVL (0xFFFFu)
149 #define ADI_GPIO_PORT2_PIN_AVL (0xFFFFu)
151 #if defined(__ADUCM4x50__)
152 #define ADI_GPIO_PORT3_PIN_AVL (0x000Fu)
153 #endif /* __ADUCM4x50__ */
154 
155 /* GPIO API functions */
156 ADI_GPIO_RESULT adi_gpio_Init (void* const pMemory, uint32_t const MemorySize);
157 ADI_GPIO_RESULT adi_gpio_UnInit (void);
158 ADI_GPIO_RESULT adi_gpio_RegisterCallback (const ADI_GPIO_IRQ eIrq, ADI_CALLBACK const pfCallback, void *const pCBParam );
159 ADI_GPIO_RESULT adi_gpio_SetGroupInterruptPins (const ADI_GPIO_PORT Port, const ADI_GPIO_IRQ eIrq, const ADI_GPIO_DATA Pins);
160 ADI_GPIO_RESULT adi_gpio_GetGroupInterruptPins (const ADI_GPIO_PORT Port, const ADI_GPIO_IRQ eIrq, ADI_GPIO_DATA* const pValue);
161 ADI_GPIO_RESULT adi_gpio_SetGroupInterruptPolarity (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins);
162 ADI_GPIO_RESULT adi_gpio_GetGroupInterruptPolarity (const ADI_GPIO_PORT Port, ADI_GPIO_DATA* const pValue);
163 ADI_GPIO_RESULT adi_gpio_GroupInterruptPolarityEnable (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag);
164 ADI_GPIO_RESULT adi_gpio_OutputEnable (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag);
165 ADI_GPIO_RESULT adi_gpio_GetOutputEnable (const ADI_GPIO_PORT Port, ADI_GPIO_DATA* const pValue);
166 ADI_GPIO_RESULT adi_gpio_InputEnable (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag);
167 ADI_GPIO_RESULT adi_gpio_PullUpEnable (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag);
168 ADI_GPIO_RESULT adi_gpio_DriveStrengthEnable (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag);
169 ADI_GPIO_RESULT adi_gpio_SetHigh (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins);
170 ADI_GPIO_RESULT adi_gpio_SetLow (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins);
171 ADI_GPIO_RESULT adi_gpio_Toggle (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins);
172 ADI_GPIO_RESULT adi_gpio_SetData (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins);
173 ADI_GPIO_RESULT adi_gpio_GetData (const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, uint16_t* const pValue);
174 ADI_GPIO_RESULT adi_gpio_GetOutputData (const ADI_GPIO_PORT Port, ADI_GPIO_DATA* const pValue);
175 #if defined (__ICCARM__)
176 #pragma diag_default=Pm011
177 #endif
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
185 #endif /* ADI_GPIO_V1_H */
ADI_GPIO_RESULT adi_gpio_GetOutputEnable(const ADI_GPIO_PORT Port, ADI_GPIO_DATA *const pValue)
Gets the Output Driver Status for GPIO Pin(s)
Definition: adi_gpio.c:664
ADI_GPIO_IRQ_TRIGGER_CONDITION
Definition: adi_gpio.h:102
ADI_GPIO_RESULT adi_gpio_GroupInterruptPolarityEnable(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag)
Determine if the interrupts are generated on the rising or falling edge of the corresponding GPIO pin...
Definition: adi_gpio.c:486
ADI_GPIO_RESULT adi_gpio_SetData(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins)
Sets the logic level of all GPIO pins on the given port to a given logic level.
Definition: adi_gpio.c:992
ADI_GPIO_RESULT adi_gpio_GetData(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, uint16_t *const pValue)
Gets/Senses the input level of all GPIO Pins on the given port.
Definition: adi_gpio.c:1063
ADI_GPIO_RESULT adi_gpio_SetHigh(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins)
Sets the Given GPIO pin(s) to a Logical High Level.
Definition: adi_gpio.c:835
ADI_GPIO_RESULT adi_gpio_SetLow(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins)
Sets the Given GPIO pin(s) to a Logical Low Level.
Definition: adi_gpio.c:887
ADI_GPIO_RESULT adi_gpio_InputEnable(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag)
Enables/Disables the Input Drivers for GPIO Pin(s)
Definition: adi_gpio.c:612
ADI_GPIO_RESULT adi_gpio_PullUpEnable(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag)
Enables/Disables the Pull-Up for GPIO Pin(s)
Definition: adi_gpio.c:716
ADI_GPIO_PORT
Definition: adi_gpio.h:118
ADI_GPIO_RESULT
Definition: adi_gpio.h:85
ADI_GPIO_RESULT adi_gpio_Init(void *const pMemory, uint32_t const MemorySize)
Initializes the GPIO functions.
Definition: adi_gpio.c:172
ADI_GPIO_RESULT adi_gpio_Toggle(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins)
Toggles the Logical Level of the Given GPIO pin(s)
Definition: adi_gpio.c:942
ADI_GPIO_RESULT adi_gpio_DriveStrengthEnable(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag)
Enables/Disables increased Drive Strength capability for GPIO Pin(s)
Definition: adi_gpio.c:776
ADI_GPIO_RESULT adi_gpio_GetGroupInterruptPins(const ADI_GPIO_PORT Port, const ADI_GPIO_IRQ eIrq, ADI_GPIO_DATA *const pValue)
Get a port&#39;s pin interrupt Group A/B mask register.
Definition: adi_gpio.c:327
ADI_GPIO_RESULT adi_gpio_GetOutputData(const ADI_GPIO_PORT Port, ADI_GPIO_DATA *const pValue)
Gets the Output Level of all GPIO Pins on a given port.
Definition: adi_gpio.c:1106
ADI_GPIO_IRQ
Definition: adi_gpio.h:111
ADI_GPIO_RESULT adi_gpio_UnInit(void)
Un-initialize the GPIO driver.
Definition: adi_gpio.c:226
ADI_GPIO_RESULT adi_gpio_OutputEnable(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins, const bool bFlag)
Enables/Disables the Output Drivers for GPIO Pin(s)
Definition: adi_gpio.c:549
ADI_GPIO_RESULT adi_gpio_SetGroupInterruptPolarity(const ADI_GPIO_PORT Port, const ADI_GPIO_DATA Pins)
Set/clear the interrupt polarity for the given pins.
Definition: adi_gpio.c:391
ADI_GPIO_RESULT adi_gpio_GetGroupInterruptPolarity(const ADI_GPIO_PORT Port, ADI_GPIO_DATA *const pValue)
Get a port&#39;s pin interrupt polarity register.
Definition: adi_gpio.c:436
ADI_GPIO_RESULT adi_gpio_SetGroupInterruptPins(const ADI_GPIO_PORT Port, const ADI_GPIO_IRQ eIrq, const ADI_GPIO_DATA Pins)
Group the pins for the given group interrupt.
Definition: adi_gpio.c:269
uint16_t ADI_GPIO_DATA
Definition: adi_gpio.h:81
ADI_GPIO_RESULT adi_gpio_RegisterCallback(const ADI_GPIO_IRQ eIrq, ADI_CALLBACK const pfCallback, void *const pCBParam)
Register or unregister an application callback function for group (A/B) interrupts.
Definition: adi_gpio.c:1160