static int lpc17_configalternate(lpc17_pinset_t cfgset, unsigned int port, unsigned int pin, uint32_t alt) { /* First, configure the port as an input so that we have a known * starting point and consistent behavior during the re-configuration. */ (void)lpc17_configinput(DEFAULT_INPUT, port, pin); /* Set up PINSEL registers */ /* Configure as GPIO */ lpc17_pinsel(port, pin, alt); /* Set pull-up mode */ lpc17_pullup(cfgset, port, pin); /* Check for open drain output */ if ((cfgset & GPIO_OPEN_DRAIN) != 0) { /* Select open drain output */ lpc17_setopendrain(port, pin); } return OK; }
static inline int lpc17_configoutput(lpc17_pinset_t cfgset, unsigned int port, unsigned int pin) { uint32_t fiobase; uint32_t regval; /* First, configure the port as a generic input so that we have a known * starting point and consistent behavior during the re-configuration. */ (void)lpc17_configinput(DEFAULT_INPUT, port, pin); /* Check for open drain output */ if ((cfgset & GPIO_OPEN_DRAIN) != 0) { /* Set pull-up mode. This normally only applies to input pins, but does have * meaning if the port is an open drain output. */ lpc17_pullup(cfgset, port, pin); /* Select open drain output */ lpc17_setopendrain(port, pin); } /* Set the initial value of the output */ lpc17_gpiowrite(cfgset, ((cfgset & GPIO_VALUE) != GPIO_VALUE_ZERO)); /* Now, reconfigure the pin as an output */ fiobase = g_fiobase[port]; regval = getreg32(fiobase + LPC17_FIO_DIR_OFFSET); regval |= (1 << pin); putreg32(regval, fiobase + LPC17_FIO_DIR_OFFSET); return OK; }