Beispiel #1
0
/**
 * \brief Configure the interrupt trigger on the given GPIO pins
 *
 * Sets the Pin direction, analog/digital mode, and pull-up configuration of
 * or a set of GPIO pins on a given GPIO port.
 *
 * @param[in] gpioport GPIO block register address base @ref gpio_reg_base
 * @param[in] trigger Trigger configuration (@ref gpio_trigger) \n
 *		      - GPIO_TRIG_LVL_LOW -- Trigger on low level \n
 *		      - GPIO_TRIG_LVL_HIGH -- Trigger on high level \n
 *		      - GPIO_TRIG_EDGE_FALL -- Trigger on falling edges \n
 *		      - GPIO_TRIG_EDGE_RISE -- Trigger on rising edges \n
 *		      - GPIO_TRIG_EDGE_BOTH -- Trigger on all edges
 * @param[in] gpios @ref gpio_pin_id. Any combination of pins may be specified
 *		    by OR'ing then together
 */
void gpio_configure_trigger(uint32_t gpioport, enum gpio_trigger trigger,
			    uint8_t gpios)
{
	switch (trigger) {
	case GPIO_TRIG_LVL_LOW:
		GPIO_IS(gpioport) |= gpios;
		GPIO_IEV(gpioport) &= ~gpios;
		break;
	case GPIO_TRIG_LVL_HIGH:
		GPIO_IS(gpioport) |= gpios;
		GPIO_IEV(gpioport) |= gpios;
		break;
	case GPIO_TRIG_EDGE_FALL:
		GPIO_IS(gpioport) &= ~gpios;
		GPIO_IBE(gpioport) &= ~gpios;
		GPIO_IEV(gpioport) &= ~gpios;
		break;
	case GPIO_TRIG_EDGE_RISE:
		GPIO_IS(gpioport) &= ~gpios;
		GPIO_IBE(gpioport) &= ~gpios;
		GPIO_IEV(gpioport) |= gpios;
		break;
	case GPIO_TRIG_EDGE_BOTH:
		GPIO_IS(gpioport) &= ~gpios;
		GPIO_IBE(gpioport) |= gpios;
		break;
	default:
		/* Don't do anything */
		break;
	}
}
Beispiel #2
0
/*
 * IRQ setup:
 * Trigger an interrupt whenever a button is depressed.
 */
static void irq_setup(void)
{
	const u32 btnpins = USR_SW1 | USR_SW2;
	/* Configure interrupt as edge-sensitive */
	GPIO_IS(GPIOF) &= ~btnpins;
	/* Interrupt only respond to rising or falling edge (single-edge) */
	GPIO_IBE(GPIOF) &= ~btnpins;
	/* Trigger interrupt on rising-edge (when button is depressed) */
	GPIO_IEV(GPIOF) |= btnpins;
	/* Finally, Enable interrupt */
	GPIO_IM(GPIOF) |= btnpins;
	/* Enable the interrupt in the NVIC as well */
	nvic_enable_irq(NVIC_GPIOF_IRQ);
}