NXP's driver library for LPC17xx, ported to mbed's online compiler. Not tested! I had to fix a lot of warings and found a couple of pretty obvious bugs, so the chances are there are more. Original: http://ics.nxp.com/support/documents/microcontrollers/zip/lpc17xx.cmsis.driver.library.zip
lpc17xx_pinsel.c
00001 /** 00002 * @file : lpc17xx_pinsel.c 00003 * @brief : Contains all functions support for Pin connect block firmware 00004 * library on LPC17xx 00005 * @version : 1.0 00006 * @date : 25. Feb. 2009 00007 * @author : HoanTran 00008 ************************************************************************** 00009 * Software that is described herein is for illustrative purposes only 00010 * which provides customers with programming information regarding the 00011 * products. This software is supplied "AS IS" without any warranties. 00012 * NXP Semiconductors assumes no responsibility or liability for the 00013 * use of the software, conveys no license or title under any patent, 00014 * copyright, or mask work right to the product. NXP Semiconductors 00015 * reserves the right to make changes in the software without 00016 * notification. NXP Semiconductors also make no representation or 00017 * warranty that such application will be suitable for the specified 00018 * use without further testing or modification. 00019 **********************************************************************/ 00020 00021 /* Peripheral group ----------------------------------------------------------- */ 00022 /** @addtogroup PINSEL 00023 * @{ 00024 */ 00025 00026 /* Includes ------------------------------------------------------------------- */ 00027 #include "lpc17xx_pinsel.h" 00028 00029 00030 /* Public Functions ----------------------------------------------------------- */ 00031 /** @addtogroup PINSEL_Public_Functions 00032 * @{ 00033 */ 00034 00035 /*********************************************************************//** 00036 * @brief Setup the pin selection function 00037 * @param[in] portnum PORT number, 00038 * should be one of the following: 00039 * - PINSEL_PORT_0 : Port 0 00040 * - PINSEL_PORT_1 : Port 1 00041 * - PINSEL_PORT_2 : Port 2 00042 * - PINSEL_PORT_3 : Port 3 00043 * 00044 * @param[in] pinnum Pin number, 00045 * should be one of the following: 00046 - PINSEL_PIN_0 : Pin 0 00047 - PINSEL_PIN_1 : Pin 1 00048 - PINSEL_PIN_2 : Pin 2 00049 - PINSEL_PIN_3 : Pin 3 00050 - PINSEL_PIN_4 : Pin 4 00051 - PINSEL_PIN_5 : Pin 5 00052 - PINSEL_PIN_6 : Pin 6 00053 - PINSEL_PIN_7 : Pin 7 00054 - PINSEL_PIN_8 : Pin 8 00055 - PINSEL_PIN_9 : Pin 9 00056 - PINSEL_PIN_10 : Pin 10 00057 - PINSEL_PIN_11 : Pin 11 00058 - PINSEL_PIN_12 : Pin 12 00059 - PINSEL_PIN_13 : Pin 13 00060 - PINSEL_PIN_14 : Pin 14 00061 - PINSEL_PIN_15 : Pin 15 00062 - PINSEL_PIN_16 : Pin 16 00063 - PINSEL_PIN_17 : Pin 17 00064 - PINSEL_PIN_18 : Pin 18 00065 - PINSEL_PIN_19 : Pin 19 00066 - PINSEL_PIN_20 : Pin 20 00067 - PINSEL_PIN_21 : Pin 21 00068 - PINSEL_PIN_22 : Pin 22 00069 - PINSEL_PIN_23 : Pin 23 00070 - PINSEL_PIN_24 : Pin 24 00071 - PINSEL_PIN_25 : Pin 25 00072 - PINSEL_PIN_26 : Pin 26 00073 - PINSEL_PIN_27 : Pin 27 00074 - PINSEL_PIN_28 : Pin 28 00075 - PINSEL_PIN_29 : Pin 29 00076 - PINSEL_PIN_30 : Pin 30 00077 - PINSEL_PIN_31 : Pin 31 00078 00079 * @param[in] funcnum Function number, 00080 * should be one of the following: 00081 * - PINSEL_FUNC_0 : default function 00082 * - PINSEL_FUNC_1 : first alternate function 00083 * - PINSEL_FUNC_2 : second alternate function 00084 * - PINSEL_FUNC_3 : third alternate function 00085 * 00086 * @return None 00087 **********************************************************************/ 00088 void PINSEL_SetPinFunc ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum) 00089 { 00090 uint32_t pinnum_t = pinnum; 00091 uint32_t pinselreg_idx = 2 * portnum; 00092 uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINSEL0; 00093 00094 if (pinnum_t >= 16) { 00095 pinnum_t -= 16; 00096 pinselreg_idx++; 00097 } 00098 *(uint32_t *)(pPinCon + pinselreg_idx) &= ~(0x03UL << (pinnum_t * 2)); 00099 *(uint32_t *)(pPinCon + pinselreg_idx) |= ((uint32_t)funcnum) << (pinnum_t * 2); 00100 } 00101 00102 00103 00104 /*********************************************************************//** 00105 * @brief Configure trace function 00106 * @param[in] NewState State of the Trace function configuration, 00107 * should be one of the following: 00108 * - ENABLE : Enable Trace Function 00109 * - DISABLE : Disable Trace Function 00110 * 00111 * @return None 00112 **********************************************************************/ 00113 void PINSEL_ConfigTraceFunc(FunctionalState NewState) 00114 { 00115 if (NewState == ENABLE) { 00116 LPC_PINCON->PINSEL10 |= (0x01UL << 3); 00117 } else if (NewState == DISABLE) { 00118 LPC_PINCON->PINSEL10 &= ~(0x01UL << 3); 00119 } 00120 } 00121 00122 00123 00124 /*********************************************************************//** 00125 * @brief Setup resistor mode for each pin 00126 * @param[in] portnum PORT number, 00127 * should be one of the following: 00128 * - PINSEL_PORT_0 : Port 0 00129 * - PINSEL_PORT_1 : Port 1 00130 * - PINSEL_PORT_2 : Port 2 00131 * - PINSEL_PORT_3 : Port 3 00132 * @param[in] pinnum Pin number, 00133 * should be one of the following: 00134 - PINSEL_PIN_0 : Pin 0 00135 - PINSEL_PIN_1 : Pin 1 00136 - PINSEL_PIN_2 : Pin 2 00137 - PINSEL_PIN_3 : Pin 3 00138 - PINSEL_PIN_4 : Pin 4 00139 - PINSEL_PIN_5 : Pin 5 00140 - PINSEL_PIN_6 : Pin 6 00141 - PINSEL_PIN_7 : Pin 7 00142 - PINSEL_PIN_8 : Pin 8 00143 - PINSEL_PIN_9 : Pin 9 00144 - PINSEL_PIN_10 : Pin 10 00145 - PINSEL_PIN_11 : Pin 11 00146 - PINSEL_PIN_12 : Pin 12 00147 - PINSEL_PIN_13 : Pin 13 00148 - PINSEL_PIN_14 : Pin 14 00149 - PINSEL_PIN_15 : Pin 15 00150 - PINSEL_PIN_16 : Pin 16 00151 - PINSEL_PIN_17 : Pin 17 00152 - PINSEL_PIN_18 : Pin 18 00153 - PINSEL_PIN_19 : Pin 19 00154 - PINSEL_PIN_20 : Pin 20 00155 - PINSEL_PIN_21 : Pin 21 00156 - PINSEL_PIN_22 : Pin 22 00157 - PINSEL_PIN_23 : Pin 23 00158 - PINSEL_PIN_24 : Pin 24 00159 - PINSEL_PIN_25 : Pin 25 00160 - PINSEL_PIN_26 : Pin 26 00161 - PINSEL_PIN_27 : Pin 27 00162 - PINSEL_PIN_28 : Pin 28 00163 - PINSEL_PIN_29 : Pin 29 00164 - PINSEL_PIN_30 : Pin 30 00165 - PINSEL_PIN_31 : Pin 31 00166 00167 * @param[in] modenum: Mode number, 00168 * should be one of the following: 00169 - PINSEL_PINMODE_PULLUP : Internal pull-up resistor 00170 - PINSEL_PINMODE_TRISTATE : Tri-state 00171 - PINSEL_PINMODE_PULLDOWN : Internal pull-down resistor 00172 00173 * @return None 00174 **********************************************************************/ 00175 void PINSEL_SetResistorMode ( uint8_t portnum, uint8_t pinnum, uint8_t modenum) 00176 { 00177 uint32_t pinnum_t = pinnum; 00178 uint32_t pinmodereg_idx = 2 * portnum; 00179 uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE0; 00180 00181 if (pinnum_t >= 16) { 00182 pinnum_t -= 16; 00183 pinmodereg_idx++ ; 00184 } 00185 00186 *(uint32_t *)(pPinCon + pinmodereg_idx) &= ~(0x03UL << (pinnum_t * 2)); 00187 *(uint32_t *)(pPinCon + pinmodereg_idx) |= ((uint32_t)modenum) << (pinnum_t * 2); 00188 } 00189 00190 00191 00192 /*********************************************************************//** 00193 * @brief Setup Open drain mode for each pin 00194 * @param[in] portnum PORT number, 00195 * should be one of the following: 00196 * - PINSEL_PORT_0 : Port 0 00197 * - PINSEL_PORT_1 : Port 1 00198 * - PINSEL_PORT_2 : Port 2 00199 * - PINSEL_PORT_3 : Port 3 00200 * 00201 * @param[in] pinnum Pin number, 00202 * should be one of the following: 00203 - PINSEL_PIN_0 : Pin 0 00204 - PINSEL_PIN_1 : Pin 1 00205 - PINSEL_PIN_2 : Pin 2 00206 - PINSEL_PIN_3 : Pin 3 00207 - PINSEL_PIN_4 : Pin 4 00208 - PINSEL_PIN_5 : Pin 5 00209 - PINSEL_PIN_6 : Pin 6 00210 - PINSEL_PIN_7 : Pin 7 00211 - PINSEL_PIN_8 : Pin 8 00212 - PINSEL_PIN_9 : Pin 9 00213 - PINSEL_PIN_10 : Pin 10 00214 - PINSEL_PIN_11 : Pin 11 00215 - PINSEL_PIN_12 : Pin 12 00216 - PINSEL_PIN_13 : Pin 13 00217 - PINSEL_PIN_14 : Pin 14 00218 - PINSEL_PIN_15 : Pin 15 00219 - PINSEL_PIN_16 : Pin 16 00220 - PINSEL_PIN_17 : Pin 17 00221 - PINSEL_PIN_18 : Pin 18 00222 - PINSEL_PIN_19 : Pin 19 00223 - PINSEL_PIN_20 : Pin 20 00224 - PINSEL_PIN_21 : Pin 21 00225 - PINSEL_PIN_22 : Pin 22 00226 - PINSEL_PIN_23 : Pin 23 00227 - PINSEL_PIN_24 : Pin 24 00228 - PINSEL_PIN_25 : Pin 25 00229 - PINSEL_PIN_26 : Pin 26 00230 - PINSEL_PIN_27 : Pin 27 00231 - PINSEL_PIN_28 : Pin 28 00232 - PINSEL_PIN_29 : Pin 29 00233 - PINSEL_PIN_30 : Pin 30 00234 - PINSEL_PIN_31 : Pin 31 00235 00236 * @param[in] modenum Open drain mode number, 00237 * should be one of the following: 00238 * - PINSEL_PINMODE_NORMAL : Pin is in the normal (not open drain) mode 00239 * - PINSEL_PINMODE_OPENDRAIN : Pin is in the open drain mode 00240 * 00241 * @return None 00242 **********************************************************************/ 00243 void PINSEL_SetOpenDrainMode( uint8_t portnum, uint8_t pinnum, uint8_t modenum) 00244 { 00245 uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE_OD0; 00246 00247 if (modenum == PINSEL_PINMODE_OPENDRAIN){ 00248 *(uint32_t *)(pPinCon + portnum) |= (0x01UL << pinnum); 00249 } else { 00250 *(uint32_t *)(pPinCon + portnum) &= ~(0x01UL << pinnum); 00251 } 00252 } 00253 00254 00255 00256 /*********************************************************************//** 00257 * @brief Setup I2C0 pins 00258 * @param[in] i2cPinMode I2C pin mode, 00259 * should be one of the following: 00260 * - PINSEL_I2C_Normal_Mode : The standard drive mode 00261 * - PINSEL_I2C_Fast_Mode : Fast Mode Plus drive mode 00262 * 00263 * @param[in] filterSlewRateEnable should be: 00264 * - ENABLE: Enable filter and slew rate. 00265 * - DISABLE: Disable filter and slew rate. 00266 * 00267 * @return None 00268 **********************************************************************/ 00269 void PINSEL_SetI2C0Pins(uint8_t i2cPinMode, FunctionalState filterSlewRateEnable) 00270 { 00271 uint32_t regVal=0; 00272 00273 if (i2cPinMode == PINSEL_I2C_Fast_Mode){ 00274 regVal |= PINSEL_I2CPADCFG_SCLDRV0 | PINSEL_I2CPADCFG_SDADRV0; 00275 } 00276 00277 if (filterSlewRateEnable == DISABLE){ 00278 regVal |= PINSEL_I2CPADCFG_SCLI2C0 | PINSEL_I2CPADCFG_SDAI2C0; 00279 } 00280 LPC_PINCON->I2CPADCFG = regVal; 00281 } 00282 00283 00284 /*********************************************************************//** 00285 * @brief Configure Pin corresponding to specified parameters passed 00286 * in the PinCfg 00287 * @param[in] PinCfg Pointer to a PINSEL_CFG_Type structure 00288 * that contains the configuration information for the 00289 * specified pin. 00290 * @return None 00291 **********************************************************************/ 00292 void PINSEL_ConfigPin(PINSEL_CFG_Type *PinCfg) 00293 { 00294 PINSEL_SetPinFunc(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Funcnum); 00295 PINSEL_SetResistorMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Pinmode); 00296 PINSEL_SetOpenDrainMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->OpenDrain); 00297 } 00298 00299 00300 /** 00301 * @} 00302 */ 00303 00304 /** 00305 * @} 00306 */ 00307 00308 /* --------------------------------- End Of File ------------------------------ */
Generated on Tue Jul 12 2022 17:06:02 by 1.7.2