LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gpio_001.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_001_H_
33 #define __GPIO_001_H_
34 
35 #include "sys_config.h"
36 #include "cmsis.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
47 #define GPIO_PORT_BITS 32
48 
49 #if defined(CHIP_LPC11UXX)
50 #define GPIO_PORT_COUNT 2
51 #endif
52 
53 #if defined(CHIP_LPC18XX) || defined(CHIP_LPC43XX)
54 #define GPIO_PORT_COUNT 6
55 #endif
56 
60 typedef struct {
61  __IO uint8_t B[GPIO_PORT_COUNT][32];
62  __I uint8_t RESERVED0[4096 - (GPIO_PORT_COUNT * 32 * sizeof(uint8_t))];
63  __IO uint32_t W[GPIO_PORT_COUNT][32];
64  __I uint8_t RESERVED1[4096 - (GPIO_PORT_COUNT * 32 * sizeof(uint32_t))];
65  __IO uint32_t DIR[GPIO_PORT_COUNT];
66  __I uint32_t RESERVED2[32 - GPIO_PORT_COUNT];
67  __IO uint32_t MASK[GPIO_PORT_COUNT];
68  __I uint32_t RESERVED3[32 - GPIO_PORT_COUNT];
69  __IO uint32_t PIN[GPIO_PORT_COUNT];
70  __I uint32_t RESERVED4[32 - GPIO_PORT_COUNT];
71  __IO uint32_t MPIN[GPIO_PORT_COUNT];
72  __I uint32_t RESERVED5[32 - GPIO_PORT_COUNT];
73  __IO uint32_t SET[GPIO_PORT_COUNT];
74  __I uint32_t RESERVED6[32 - GPIO_PORT_COUNT];
75  __O uint32_t CLR[GPIO_PORT_COUNT];
76  __I uint32_t RESERVED7[32 - GPIO_PORT_COUNT];
77  __O uint32_t NOT[GPIO_PORT_COUNT];
79 
86 {}
87 
96 STATIC INLINE void IP_GPIO_WritePortBit(IP_GPIO_001_Type *pGPIO, uint32_t Port, uint8_t Bit, bool Setting)
97 {
98  pGPIO->B[Port][Bit] = Setting;
99 }
100 
109 STATIC INLINE void IP_GPIO_WriteDirBit(IP_GPIO_001_Type *pGPIO, uint32_t Port, uint8_t Bit, bool Setting)
110 {
111  if (Setting) {
112  pGPIO->DIR[Port] |= 1UL << Bit;
113  }
114  else {
115  pGPIO->DIR[Port] &= ~(1UL << Bit);
116  }
117 }
118 
127 {
128  return (bool) pGPIO->B[Port][Bit];
129 }
130 
139 {
140  return (bool) (((pGPIO->DIR[Port]) >> Bit) & 1);
141 }
142 
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif /* __GPIO_001_H_ */