| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gpio_003.h
Go to the documentation of this file.
1 /*
2 * @brief GPIO Registers and Functions
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #ifndef __GPIO_003_H_
33 #define __GPIO_003_H_
34
35 #include "sys_config.h"
36 #include "cmsis.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
50 typedef struct {
51 __IO uint32_t DATA[4096];
52 uint32_t RESERVED1[4096];
53 __IO uint32_t DIR;
54 __IO uint32_t IS;
55 __IO uint32_t IBE;
56 __IO uint32_t IEV;
57 __IO uint32_t IE;
58 __I uint32_t RIS;
59 __I uint32_t MIS;
60 __O uint32_t IC;
61 } IP_GPIO_003_T;
62
68 STATIC INLINE void IP_GPIO_Init(IP_GPIO_003_T *pGPIO)
69 {}
70
80 STATIC INLINE void IP_GPIO_WritePort(IP_GPIO_003_T *pGPIO, uint16_t mask, uint16_t val)
81 {
82 pGPIO->DATA[mask] = val;
83 }
84
92 STATIC INLINE void IP_GPIO_WritePortBit(IP_GPIO_003_T *pGPIO, uint8_t pin, bool val)
93 {
94 pGPIO->DATA[1 << pin] = val << pin;
95 }
96
102 STATIC INLINE uint32_t IP_GPIO_ReadPort(IP_GPIO_003_T *pGPIO)
103 {
104 return pGPIO->DATA[4095];
105 }
106
113 STATIC INLINE bool IP_GPIO_ReadPortBit(IP_GPIO_003_T *pGPIO, uint8_t pin)
114 {
115 return (bool) ((pGPIO->DATA[1 << pin] >> pin) & 1);
116 }
117
125 STATIC INLINE void IP_GPIO_WriteDirBit(IP_GPIO_003_T *pGPIO, uint8_t pin, bool dir)
126 {
127 if (dir) {
128 pGPIO->DIR |= 1UL << pin;
129 }
130 else {
131 pGPIO->DIR &= ~(1UL << pin);
132 }
133 }
134
142 STATIC INLINE void IP_GPIO_SetDir(IP_GPIO_003_T *pGPIO, uint32_t bitVal, bool dir)
143 {
144 if (dir) {
145 pGPIO->DIR |= bitVal;
146 }
147 else {
148 pGPIO->DIR &= ~bitVal;
149 }
150 }
151
158 STATIC INLINE bool IP_GPIO_ReadDirBit(IP_GPIO_003_T *pGPIO, uint8_t pin)
159 {
160 return (bool) (((pGPIO->DIR) >> pin) & 1);
161 }
162
163 typedef enum {
164 GPIOPININT_FALLING_EDGE = 0,
165 GPIOPININT_ACTIVE_LOW_LEVEL = 1,
166 GPIOPININT_RISING_EDGE = (1 << 12),
167 GPIOPININT_ACTIVE_HIGH_LEVEL = 1 | (1 << 12),
168 GPIOPININT_BOTH_EDGES = (1 << 24),
169 } IP_GPIOPININT_MODE_T;
170
178 void IP_GPIO_IntCmd(IP_GPIO_003_T *pGPIO, uint8_t pin, IP_GPIOPININT_MODE_T mode);
179
186 STATIC INLINE bool IP_GPIO_IntGetStatus(IP_GPIO_003_T *pGPIO, uint8_t pin)
187 {
188 return (bool) (((pGPIO->RIS) >> pin) & 0x01);
189 }
190
197 STATIC INLINE void IP_GPIO_IntClear(IP_GPIO_003_T *pGPIO, uint8_t pin)
198 {
199 pGPIO->IC |= (1 << pin);
200 }
201
206 #ifdef __cplusplus
207 }
208 #endif
209
210 #endif /* __GPIO_003_H_ */