uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc17xx_pinsel.c
Go to the documentation of this file.
1 /***********************************************************************/
21 /* Peripheral group ----------------------------------------------------------- */
26 /* Includes ------------------------------------------------------------------- */
27 #include "lpc17xx_pinsel.h"
28 
29 /* Public Functions ----------------------------------------------------------- */
30 
31 static void set_PinFunc ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum);
32 static void set_ResistorMode ( uint8_t portnum, uint8_t pinnum, uint8_t modenum);
33 static void set_OpenDrainMode( uint8_t portnum, uint8_t pinnum, uint8_t modenum);
34 
35 /*********************************************************************/
88 static void set_PinFunc ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum)
89 {
90  uint32_t pinnum_t = pinnum;
91  uint32_t pinselreg_idx = 2 * portnum;
92  uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINSEL0;
93 
94  if (pinnum_t >= 16) {
95  pinnum_t -= 16;
96  pinselreg_idx++;
97  }
98  *(uint32_t *)(pPinCon + pinselreg_idx) &= ~(0x03UL << (pinnum_t * 2));
99  *(uint32_t *)(pPinCon + pinselreg_idx) |= ((uint32_t)funcnum) << (pinnum_t * 2);
100 }
101 
102 /*********************************************************************/
153 void set_ResistorMode ( uint8_t portnum, uint8_t pinnum, uint8_t modenum)
154 {
155  uint32_t pinnum_t = pinnum;
156  uint32_t pinmodereg_idx = 2 * portnum;
157  uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE0;
158 
159  if (pinnum_t >= 16) {
160  pinnum_t -= 16;
161  pinmodereg_idx++ ;
162  }
163 
164  *(uint32_t *)(pPinCon + pinmodereg_idx) &= ~(0x03UL << (pinnum_t * 2));
165  *(uint32_t *)(pPinCon + pinmodereg_idx) |= ((uint32_t)modenum) << (pinnum_t * 2);
166 }
167 
168 /*********************************************************************/
219 void set_OpenDrainMode( uint8_t portnum, uint8_t pinnum, uint8_t modenum)
220 {
221  uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE_OD0;
222 
223  if (modenum == PINSEL_PINMODE_OPENDRAIN){
224  *(uint32_t *)(pPinCon + portnum) |= (0x01UL << pinnum);
225  } else {
226  *(uint32_t *)(pPinCon + portnum) &= ~(0x01UL << pinnum);
227  }
228 }
229 
230 /* End of Public Functions ---------------------------------------------------- */
231 
232 /* Public Functions ----------------------------------------------------------- */
236 /*********************************************************************/
246 {
247  if (NewState == ENABLE) {
248  LPC_PINCON->PINSEL10 |= (0x01UL << 3);
249  } else if (NewState == DISABLE) {
250  LPC_PINCON->PINSEL10 &= ~(0x01UL << 3);
251  }
252 }
253 
254 /*********************************************************************/
267 void PINSEL_SetI2C0Pins(uint8_t i2cPinMode, FunctionalState filterSlewRateEnable)
268 {
269  uint32_t regVal;
270 
271  if (i2cPinMode == PINSEL_I2C_Fast_Mode){
273  }
274 
275  if (filterSlewRateEnable == DISABLE){
277  }
278  LPC_PINCON->I2CPADCFG = regVal;
279 }
280 
281 
282 /*********************************************************************/
291 {
292  set_PinFunc(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Funcnum);
293  set_ResistorMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Pinmode);
294  set_OpenDrainMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->OpenDrain);
295 }
296 
297 
306 /* --------------------------------- End Of File ------------------------------ */