1 /*
2  * @brief Grouped GPIO Interrupt example
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2013
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 #include "board.h"
33 
34 /*****************************************************************************
35  * Private types/enumerations/variables
36  ****************************************************************************/
37 
38 #if defined(BOARD_NXP_LPCXPRESSO_1549)
39 
40 /* GPIO pin for GROUPED GPIO interrupt.  This is SW1-WAKE button switch input. */
41 #define TEST_BUTTON_PIN         17	/* GPIO pin number mapped to PININT */
42 #define TEST_BUTTON_PORT        0	/* GPIO port number mapped to PININT */
43 
44 #else
45 #error "Grouped GPIO Interrupt not configured for this example"
46 #endif /* defined(BOARD_NXP_LPCXPRESSO_1549) */
47 
48 /*****************************************************************************
49  * Public types/enumerations/variables
50  ****************************************************************************/
51 
52 /*****************************************************************************
53  * Private functions
54  ****************************************************************************/
55 
56 /*****************************************************************************
57  * Public functions
58  ****************************************************************************/
59 
60 /**
61  * @brief	Handle Group GPIO 0 interrupt
62  * @return	Nothing
63  */
GINT0_IRQHandler(void)64 void GINT0_IRQHandler(void)
65 {
66 	Chip_GPIOGP_ClearIntStatus(LPC_GPIOGROUP, 0);
67 	Board_LED_Toggle(0);
68 }
69 
70 /**
71  * @brief	Main program body
72  * @return	Does not return
73  */
main(void)74 int main(void)
75 {
76 	/* Generic Initialization */
77 	SystemCoreClockUpdate();
78 	Board_Init();
79 	Board_LED_Set(0, false);
80 
81 	/* Initialize GPIO grouped interrupts */
82 	Chip_GPIOGP_Init(LPC_GPIOGROUP);
83 
84 	/* Set pin back to GPIO (on some boards may have been changed to something
85 	   else by Board_Init()) */
86 	Chip_IOCON_PinMuxSet(LPC_IOCON, TEST_BUTTON_PORT, TEST_BUTTON_PIN,
87 						 (IOCON_DIGMODE_EN | IOCON_MODE_INACT) );
88 
89 	/* Group GPIO interrupt 0 will be invoked when the button is pressed. */
90 	Chip_GPIO_SetPinDIRInput(LPC_GPIO, TEST_BUTTON_PORT, TEST_BUTTON_PIN);
91 	Chip_GPIOGP_SelectLowLevel(LPC_GPIOGROUP, 0, TEST_BUTTON_PORT, 1 << TEST_BUTTON_PIN);
92 	Chip_GPIOGP_EnableGroupPins(LPC_GPIOGROUP, 0, TEST_BUTTON_PORT, 1 << TEST_BUTTON_PIN);
93 	Chip_GPIOGP_SelectAndMode(LPC_GPIOGROUP, 0);
94 	Chip_GPIOGP_SelectEdgeMode(LPC_GPIOGROUP, 0);
95 
96 	/* Enable Group GPIO interrupt 0 */
97 	NVIC_EnableIRQ(GINT0_IRQn);
98 
99 	/* Spin in a loop here.  All the work is done in ISR. */
100 	while (1) {}
101 
102 	/* Does not return */
103 	return 0;
104 }
105