lpc17xx_exti.c (5868B)
1 /********************************************************************** 2 * $Id$ lpc17xx_exti.c 2010-06-18 3 *//** 4 * @file lpc17xx_exti.c 5 * @brief Contains all functions support for External interrupt firmware 6 * library on LPC17xx 7 * @version 3.0 8 * @date 18. June. 2010 9 * @author NXP MCU SW Application Team 10 * 11 * Copyright(C) 2010, NXP Semiconductor 12 * All rights reserved. 13 * 14 *********************************************************************** 15 * Software that is described herein is for illustrative purposes only 16 * which provides customers with programming information regarding the 17 * products. This software is supplied "AS IS" without any warranties. 18 * NXP Semiconductors assumes no responsibility or liability for the 19 * use of the software, conveys no license or title under any patent, 20 * copyright, or mask work right to the product. NXP Semiconductors 21 * reserves the right to make changes in the software without 22 * notification. NXP Semiconductors also make no representation or 23 * warranty that such application will be suitable for the specified 24 * use without further testing or modification. 25 * Permission to use, copy, modify, and distribute this software and its 26 * documentation is hereby granted, under NXP Semiconductors' 27 * relevant copyright 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 /* Peripheral group ----------------------------------------------------------- */ 34 /** @addtogroup EXTI 35 * @{ 36 */ 37 38 /* Includes ------------------------------------------------------------------- */ 39 #include "lpc17xx_exti.h" 40 41 /* If this source file built with example, the LPC17xx FW library configuration 42 * file in each example directory ("lpc17xx_libcfg.h") must be included, 43 * otherwise the default FW library configuration file must be included instead 44 */ 45 #ifdef __BUILD_WITH_EXAMPLE__ 46 #include "lpc17xx_libcfg.h" 47 #else 48 #include "lpc17xx_libcfg_default.h" 49 #endif /* __BUILD_WITH_EXAMPLE__ */ 50 51 52 #ifdef _EXTI 53 54 /* Public Functions ----------------------------------------------------------- */ 55 /** @addtogroup EXTI_Public_Functions 56 * @{ 57 */ 58 59 /*********************************************************************//** 60 * @brief Initial for EXT 61 * - Set EXTINT, EXTMODE, EXTPOLAR registers to default value 62 * @param[in] None 63 * @return None 64 **********************************************************************/ 65 void EXTI_Init(void) 66 { 67 LPC_SC->EXTINT = 0xF; 68 LPC_SC->EXTMODE = 0x0; 69 LPC_SC->EXTPOLAR = 0x0; 70 } 71 72 73 /*********************************************************************//** 74 * @brief Close EXT 75 * @param[in] None 76 * @return None 77 **********************************************************************/ 78 void EXTI_DeInit(void) 79 { 80 ; 81 } 82 83 /*********************************************************************//** 84 * @brief Configuration for EXT 85 * - Set EXTINT, EXTMODE, EXTPOLAR register 86 * @param[in] EXTICfg Pointer to a EXTI_InitTypeDef structure 87 * that contains the configuration information for the 88 * specified external interrupt 89 * @return None 90 **********************************************************************/ 91 void EXTI_Config(EXTI_InitTypeDef *EXTICfg) 92 { 93 LPC_SC->EXTINT = 0x0; 94 EXTI_SetMode(EXTICfg->EXTI_Line, EXTICfg->EXTI_Mode); 95 EXTI_SetPolarity(EXTICfg->EXTI_Line, EXTICfg->EXTI_polarity); 96 } 97 98 /*********************************************************************//** 99 * @brief Set mode for EXTI pin 100 * @param[in] EXTILine external interrupt line, should be: 101 * - EXTI_EINT0: external interrupt line 0 102 * - EXTI_EINT1: external interrupt line 1 103 * - EXTI_EINT2: external interrupt line 2 104 * - EXTI_EINT3: external interrupt line 3 105 * @param[in] mode external mode, should be: 106 * - EXTI_MODE_LEVEL_SENSITIVE 107 * - EXTI_MODE_EDGE_SENSITIVE 108 * @return None 109 *********************************************************************/ 110 void EXTI_SetMode(EXTI_LINE_ENUM EXTILine, EXTI_MODE_ENUM mode) 111 { 112 if(mode == EXTI_MODE_EDGE_SENSITIVE) 113 { 114 LPC_SC->EXTMODE |= (1 << EXTILine); 115 } 116 else if(mode == EXTI_MODE_LEVEL_SENSITIVE) 117 { 118 LPC_SC->EXTMODE &= ~(1 << EXTILine); 119 } 120 } 121 122 /*********************************************************************//** 123 * @brief Set polarity for EXTI pin 124 * @param[in] EXTILine external interrupt line, should be: 125 * - EXTI_EINT0: external interrupt line 0 126 * - EXTI_EINT1: external interrupt line 1 127 * - EXTI_EINT2: external interrupt line 2 128 * - EXTI_EINT3: external interrupt line 3 129 * @param[in] polarity external polarity value, should be: 130 * - EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE 131 * - EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE 132 * @return None 133 *********************************************************************/ 134 void EXTI_SetPolarity(EXTI_LINE_ENUM EXTILine, EXTI_POLARITY_ENUM polarity) 135 { 136 if(polarity == EXTI_POLARITY_HIGH_ACTIVE_OR_RISING_EDGE) 137 { 138 LPC_SC->EXTPOLAR |= (1 << EXTILine); 139 } 140 else if(polarity == EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE) 141 { 142 LPC_SC->EXTPOLAR &= ~(1 << EXTILine); 143 } 144 } 145 146 /*********************************************************************//** 147 * @brief Clear External interrupt flag 148 * @param[in] EXTILine external interrupt line, should be: 149 * - EXTI_EINT0: external interrupt line 0 150 * - EXTI_EINT1: external interrupt line 1 151 * - EXTI_EINT2: external interrupt line 2 152 * - EXTI_EINT3: external interrupt line 3 153 * @return None 154 *********************************************************************/ 155 void EXTI_ClearEXTIFlag(EXTI_LINE_ENUM EXTILine) 156 { 157 LPC_SC->EXTINT = (1 << EXTILine); 158 } 159 160 /** 161 * @} 162 */ 163 164 #endif /* _EXTI */ 165 166 /** 167 * @} 168 */ 169 170 /* --------------------------------- End Of File ------------------------------ */ 171