LPCOpen Platform for LPC112X microcontrollers  112X
LPCOpen Platform for the NXP LPC112X family of Microcontrollers
gpio_112x.c
Go to the documentation of this file.
1 /*
2  * @brief LPC11xx GPIO driver for CHIP_LPC11CXX, CHIP_LPC110X, CHIP_LPC11XXLV,
3  * and CHIP_LPC1125 families only.
4  *
5  * @note
6  * Copyright(C) NXP Semiconductors, 2013
7  * All rights reserved.
8  *
9  * @par
10  * Software that is described herein is for illustrative purposes only
11  * which provides customers with programming information regarding the
12  * LPC products. This software is supplied "AS IS" without any warranties of
13  * any kind, and NXP Semiconductors and its licensor disclaim any and
14  * all warranties, express or implied, including all implied warranties of
15  * merchantability, fitness for a particular purpose and non-infringement of
16  * intellectual property rights. NXP Semiconductors assumes no responsibility
17  * or liability for the use of the software, conveys no license or rights under any
18  * patent, copyright, mask work right, or any other intellectual property rights in
19  * or to any products. NXP Semiconductors reserves the right to make changes
20  * in the software without notification. NXP Semiconductors also makes no
21  * representation or warranty that such application will be suitable for the
22  * specified use without further testing or modification.
23  *
24  * @par
25  * Permission to use, copy, modify, and distribute this software and its
26  * documentation is hereby granted, under NXP Semiconductors' and its
27  * licensor's relevant copyrights in the software, without fee, provided that it
28  * is used in conjunction with NXP Semiconductors microcontrollers. This
29  * copyright, permission, and disclaimer notice must appear in all copies of
30  * this code.
31  */
32 
33 #include "chip.h"
34 
35 /*****************************************************************************
36  * Private types/enumerations/variables
37  ****************************************************************************/
38 
39 /*****************************************************************************
40  * Public types/enumerations/variables
41  ****************************************************************************/
42 
43 /*****************************************************************************
44  * Private functions
45  ****************************************************************************/
46 
47 /*****************************************************************************
48  * Public functions
49  ****************************************************************************/
50 
51 /* Initialize GPIO block */
53 {
55 }
56 
57 /* De-Initialize GPIO block */
59 {
61 }
62 
63 /* Set GPIO direction */
64 void Chip_GPIO_WriteDirBit(LPC_GPIO_T *pGPIO, uint32_t port, uint8_t bit, bool setting)
65 {
66  if (setting) {
67  pGPIO[port].DIR |= 1UL << bit;
68  }
69  else {
70  pGPIO[port].DIR &= ~(1UL << bit);
71  }
72 }
73 
74 /* Set Direction for a GPIO port */
75 void Chip_GPIO_SetDir(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t bit, uint8_t out)
76 {
77  if (out) {
78  pGPIO[port].DIR |= bit;
79  }
80  else {
81  pGPIO[port].DIR &= ~bit;
82  }
83 }
84 
85 /* Set GPIO direction for a single GPIO pin */
86 void Chip_GPIO_SetPinDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, bool output)
87 {
88  if (output) {
89  Chip_GPIO_SetPinDIROutput(pGPIO, port, pin);
90  }
91  else {
92  Chip_GPIO_SetPinDIRInput(pGPIO, port, pin);
93  }
94 }
95 
96 /* Set GPIO direction for a all selected GPIO pins to an input or output */
97 void Chip_GPIO_SetPortDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinMask, bool outSet)
98 {
99  if (outSet) {
100  Chip_GPIO_SetPortDIROutput(pGPIO, port, pinMask);
101  }
102  else {
103  Chip_GPIO_SetPortDIRInput(pGPIO, port, pinMask);
104  }
105 }
106 
107 /* Composite function for setting up a full interrupt configuration for a single pin */
108 void Chip_GPIO_SetupPinInt(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, GPIO_INT_MODE_T mode)
109 {
110  uint32_t pinMask = (1 << pin);
111 
112  /* Edge mode selected? */
113  if ((uint32_t) mode & 0x2) {
114  Chip_GPIO_SetPinModeEdge(pGPIO, port, pinMask);
115 
116  /* Interrupt on both edges selected? */
117  if ((uint32_t) mode & 0x4) {
118  Chip_GPIO_SetEdgeModeBoth(pGPIO, port, pinMask);
119  }
120  else {
121  Chip_GPIO_SetEdgeModeSingle(pGPIO, port, pinMask);
122  }
123  }
124  else {
125  /* Level mode */
126  Chip_GPIO_SetPinModeLevel(pGPIO, port, pinMask);
127  }
128 
129  /* Level selections will not alter 'dual edge' mode */
130  if ((uint32_t) mode & 0x1) {
131  /* High edge or level mode selected */
132  Chip_GPIO_SetModeHigh(pGPIO, port, pinMask);
133  }
134  else {
135  Chip_GPIO_SetModeLow(pGPIO, port, pinMask);
136  }
137 }