/** @brief Set GPIO Alternate Function Selection

Set the alternate function mapping number for each pin. Most pins have
alternate functions associated with them. When set to AF mode, a pin may be
used for one of its allocated alternate functions selected by the number given
here. To determine the number to be used for the desired function refer to the
individual datasheet for the particular device. A table is given under the Pin
Selection chapter.

Note that a number of pins may be set but only with a single AF number. In
practice this would rarely be useful as each pin is likely to require a
different number.

@param[in] gpioport Unsigned int32. Port identifier @ref gpio_port_id
@param[in] alt_func_num Unsigned int8. Pin alternate function number @ref
gpio_af_num
@param[in] gpios Unsigned int16. Pin identifiers @ref gpio_pin_id
	     If multiple pins are to be set, use bitwise OR '|' to separate
	     them.
*/
void gpio_set_af(uint32_t gpioport, uint8_t alt_func_num, uint16_t gpios)
{
	uint16_t i;
	uint32_t afrl, afrh;

	afrl = GPIO_AFRL(gpioport);
	afrh = GPIO_AFRH(gpioport);

	for (i = 0; i < 8; i++) {
		if (!((1 << i) & gpios)) {
			continue;
		}
		afrl &= ~GPIO_AFR_MASK(i);
		afrl |= GPIO_AFR(i, alt_func_num);
	}

	for (i = 8; i < 16; i++) {
		if (!((1 << i) & gpios)) {
			continue;
		}
		afrh &= ~GPIO_AFR_MASK(i - 8);
		afrh |= GPIO_AFR(i - 8, alt_func_num);
	}

	GPIO_AFRL(gpioport) = afrl;
	GPIO_AFRH(gpioport) = afrh;
}
예제 #2
0
파일: gpio.c 프로젝트: 3yc/libopencm3
void gpio_set_af(u32 gpioport, u8 alt_func_num, u16 gpios)
{
	u16 i;
	u32 afrl, afrh;

	afrl = GPIO_AFRL(gpioport);
	afrh = GPIO_AFRH(gpioport);

	for (i = 0; i < 8; i++) {
		if (!((1 << i) & gpios))
			continue;
		afrl &= ~GPIO_AFR_MASK(i);
		afrl |= GPIO_AFR(i, alt_func_num);
	}

	for (i = 8; i < 16; i++) {
		if (!((1 << i) & gpios))
			continue;
		afrl &= ~GPIO_AFR_MASK(i - 8);
		afrh |= GPIO_AFR(i - 8, alt_func_num);
	}

	GPIO_AFRL(gpioport) = afrl;
	GPIO_AFRH(gpioport) = afrh;
}
예제 #3
0
파일: gpio.c 프로젝트: AIdrifter/f9-kernel
inline static void gpio_afr(uint8_t port, uint8_t pin, uint8_t func)
{
	uint32_t reg;

	if (pin < 8) {
		reg = *GPIO_AFRL(port);
		reg &= ~(GPIO_AFRL_M(pin));
		reg |= (func << GPIO_AFRL_PIN(pin));
		*GPIO_AFRL(port) = reg;
	} else {
		reg = *GPIO_AFRH(port);
		reg &= ~(GPIO_AFRH_M(pin));
		reg |= (func << GPIO_AFRH_PIN(pin));
		*GPIO_AFRH(port) = reg;
	}
}