Skip to content

Commit

Permalink
cpu/sam0: merge GPIO driver
Browse files Browse the repository at this point in the history
  • Loading branch information
dylad authored and aabadie committed Oct 1, 2017
1 parent 67244f2 commit 1e52625
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 257 deletions.
34 changes: 21 additions & 13 deletions cpu/saml21/periph/gpio.c → cpu/sam0_common/periph/gpio.c
Expand Up @@ -9,7 +9,7 @@
*/

/**
* @ingroup cpu_saml21
* @ingroup cpu_sam0_common
* @ingroup drivers_periph_gpio
* @{
*
Expand All @@ -26,6 +26,7 @@

#include "cpu.h"
#include "periph/gpio.h"
#include "periph_conf.h"

#define ENABLE_DEBUG (0)
#include "debug.h"
Expand All @@ -40,19 +41,8 @@
*/
#define MODE_PINCFG_MASK (0x06)

/**
* @brief Mapping of pins to EXTI lines, -1 means not EXTI possible
*/
static const int8_t exti_config[2][32] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, -1, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 12, 13, -1, 15, -1, -1, 10, 11},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 1, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1, 14, 15},
};

static gpio_isr_ctx_t gpio_config[NUMOF_IRQS];


static inline PortGroup *_port(gpio_t pin)
{
return (PortGroup *)(pin & ~(0x1f));
Expand Down Expand Up @@ -135,23 +125,41 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
/* configure pin as input and set MUX to peripheral function A */
gpio_init(pin, mode);
gpio_init_mux(pin, GPIO_MUX_A);
#ifdef CPU_FAM_SAMD21
/* enable clocks for the EIC module */
PM->APBAMASK.reg |= PM_APBAMASK_EIC;
/* SAMD21 used GCLK2 which is supplied by either the ultra low power
internal or external 32 kHz */
GCLK->CLKCTRL.reg = (EIC_GCLK_ID |
GCLK_CLKCTRL_CLKEN |
GCLK_CLKCTRL_GEN_GCLK2);
while (GCLK->STATUS.bit.SYNCBUSY) {}
#else /* CPU_FAM_SAML21 */
/* enable clocks for the EIC module */
MCLK->APBAMASK.reg |= MCLK_APBAMASK_EIC;
GCLK->PCHCTRL[EIC_GCLK_ID].reg = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN_GCLK0;
/* disable the EIC module*/
EIC->CTRLA.reg = 0;
while (EIC->SYNCBUSY.reg & EIC_SYNCBUSY_ENABLE) {}
#endif
/* configure the active flank */
EIC->CONFIG[exti >> 3].reg &= ~(0xf << ((exti & 0x7) * 4));
EIC->CONFIG[exti >> 3].reg |= (flank << ((exti & 0x7) * 4));
/* enable the global EIC interrupt */
NVIC_EnableIRQ(EIC_IRQn);
/*Enable pin interrupt */
/* clear interrupt flag and enable the interrupt line and line wakeup */
EIC->INTFLAG.reg = (1 << exti);
EIC->INTENSET.reg = (1 << exti);
#ifdef CPU_FAM_SAMD21
EIC->WAKEUP.reg |= (1 << exti);
/* enable the EIC module*/
EIC->CTRL.reg = EIC_CTRL_ENABLE;
while (EIC->STATUS.reg & EIC_STATUS_SYNCBUSY) {}
#else /* CPU_FAM_SAML21 */
/* enable the EIC module*/
EIC->CTRLA.reg = EIC_CTRLA_ENABLE;
while (EIC->SYNCBUSY.reg & EIC_SYNCBUSY_ENABLE) {}
#endif
return 0;
}

Expand Down
29 changes: 29 additions & 0 deletions cpu/samd21/include/periph_cpu.h
Expand Up @@ -28,6 +28,35 @@
extern "C" {
#endif

/**
* @brief Mapping of pins to EXTI lines, -1 means not EXTI possible
*/
static const int8_t exti_config[2][32] = {
#ifdef CPU_MODEL_SAMD21J18A
{ 0, 1, 2, 3, 4, 5, 6, 7, -1, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 12, 13, -1, 15, 8, -1, 10, 11},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 1, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1, 14, 15},
#elif CPU_MODEL_SAMD21G18A
{ 0, 1, 2, 3, 4, 5, 6, 7, -1, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 12, 13, -1, 15, 8, -1, 10, 11},
{-1, -1, 2, 3, -1, -1, -1, -1, 8, 9, 10, 11, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1},
#elif CPU_MODEL_SAMR21G18A
{-1, 1, -1, -1, 4, 5, 6, 7, -1, 9, 10, 11, 12, 13, 14, 15,
-1, 1, 2, 3, -1, -1, 6, 7, 12, 13, -1, 15, 8, -1, 10, 11},
{ 0, -1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, 8, -1, -1, -1},
#elif CPU_MODEL_SAMR21E18A
{-1, -1, -1, -1, -1, -1, 6, 7, -1, 9, 10, 11, -1, -1, 14, 15,
-1, 1, 2, 3, -1, -1, -1, -1, 12, 13, -1, 15, 8, -1, 10, 11},
{ 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
#else
#error Please define a proper CPU_MODEL.
#endif
};

/**
* @brief Available ports on the SAMD21
*/
Expand Down
244 changes: 0 additions & 244 deletions cpu/samd21/periph/gpio.c

This file was deleted.

10 changes: 10 additions & 0 deletions cpu/saml21/include/periph_cpu.h
Expand Up @@ -26,6 +26,16 @@
extern "C" {
#endif

/**
* @brief Mapping of pins to EXTI lines, -1 means not EXTI possible
*/
static const int8_t exti_config[2][32] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, -1, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 12, 13, -1, 15, -1, -1, 10, 11},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 1, -1, -1, -1, -1, 6, 7, -1, -1, -1, -1, -1, -1, 14, 15},
};

/**
* @brief Available ports on the SAML21 for convenient access
*/
Expand Down

0 comments on commit 1e52625

Please sign in to comment.