cpu/sam3: add gpio_init_mux() function

This commit is contained in:
Hauke Petersen 2016-12-13 15:49:57 +01:00
parent 9b312a8aae
commit 38c7d11f8c
2 changed files with 19 additions and 0 deletions

View File

@ -149,6 +149,14 @@ typedef struct {
uint8_t irqn; /**< interrupt number of the device */
} uart_conf_t;
/**
* @brief Configure the given GPIO pin to be used with the given MUX setting
*
* @param[in] pin GPIO pin to configure
* @param[in] mux MUX setting to use
*/
void gpio_init_mux(gpio_t pin, gpio_mux_t mux);
#ifdef __cplusplus
}
#endif

View File

@ -242,6 +242,17 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
return 0;
}
void gpio_init_mux(gpio_t pin, gpio_mux_t mux)
{
/* power on the corresponding port */
PMC->PMC_PCER0 = (1 << (_port_num(pin) + 11));
/* give peripheral control over the pin */
_port(pin)->PIO_PDR = (1 << _pin_num(pin));
/* and configure the MUX */
_port(pin)->PIO_ABSR &= ~(1 << _pin_num(pin));
_port(pin)->PIO_ABSR |= (mux << _pin_num(pin));
}
void gpio_irq_enable(gpio_t pin)
{
NVIC_EnableIRQ((1 << (_port_num(pin) + PIOA_IRQn)));