/* Multiplex group of pins to the given alternate function. 
Because AF0 is not used on the LM4F, passing 0 as the alt_func_num parameter will disable the alternate function of the given pins. */
void gpio_set_af(uint32_t gpioport, uint8_t alt_func_num, uint8_t gpios)
/* Multiplex group of pins to the given alternate function. 
Because AF0 is not used on the LM4F, passing 0 as the alt_func_num parameter will disable the alternate function of the given pins. */
void gpio_set_af(uint32_t gpioport, uint8_t alt_func_num, uint8_t gpios)
{
	uint32_t pctl32;
	uint8_t pin_mask;
	int i;
	if (alt_func_num == 0) {
		GPIO_AFSEL(gpioport) &= ~gpios;
		return;
	}
	GPIO_AFSEL(gpioport) |= gpios;
	GPIO_DEN(gpioport) |= gpios;
	pctl32 = GPIO_PCTL(gpioport);
	for (i = 0; i < 8; i++) {
		pin_mask = (1 << i);
		if (!(gpios & pin_mask)) {
			continue;
		}
		pctl32 &= ~PCTL_MASK(i);
		pctl32 |= PCTL_AF(i, (alt_func_num & 0xf));
	}
	GPIO_PCTL(gpioport) = pctl32;
}