diff --git a/boards/samr21-xpro/include/periph_conf.h b/boards/samr21-xpro/include/periph_conf.h index ed1f1ad2d616222286d3d833d67317879dd75746..da3d2b30952476d3df36a6b203afceba596c7d35 100644 --- a/boards/samr21-xpro/include/periph_conf.h +++ b/boards/samr21-xpro/include/periph_conf.h @@ -132,43 +132,21 @@ static const uart_conf_t uart_config[] = { #define PWM_0_CHANNELS PWM_MAX_CHANNELS #define PWM_1_CHANNELS PWM_MAX_CHANNELS -/** - * @brief PWM channel configuration data structure - * - * TODO: this should be moved into the CPU folder - */ -typedef struct { - PortGroup *port; /**< GPIO port */ - uint8_t pin; /**< GPIO pin */ - uint8_t fnct; /**< pin function multiplex value */ - uint8_t chan; /**< TCC channel to use */ -} pwm_conf_chan_t; - -/** - * @brief PWM device configuration data structure - * - * TODO: this should be moved into the CPU folder - */ -typedef struct { - Tcc *dev; /*< TCC device to use */ - pwm_conf_chan_t chan[2]; /**< channel configuration */ -} pwm_conf_t; - /* PWM device configuration */ #if PWM_NUMOF static const pwm_conf_t pwm_config[] = { #if PWM_0_EN {TCC1, { - /* port , pin, AF, chan */ - {(PortGroup *)0x41004400, 6, 4, 0}, - {(PortGroup *)0x41004400, 7, 4, 1} + /* GPIO pin, MUX value, TCC channel */ + {GPIO_PIN(PA, 6), GPIO_MUX_E, 0}, + {GPIO_PIN(PA, 7), GPIO_MUX_E, 1} }}, #endif #if PWM_1_EN {TCC0, { - /* port , pin, AF, chan */ - {(PortGroup *)0x41004400, 18, 5, 2}, - {(PortGroup *)0x41004400, 19, 5, 3} + /* GPIO pin, MUX value, TCC channel */ + {GPIO_PIN(PA, 18), GPIO_MUX_F, 2}, + {GPIO_PIN(PA, 19), GPIO_MUX_F, 3} }}, #endif }; diff --git a/cpu/samd21/include/periph_cpu.h b/cpu/samd21/include/periph_cpu.h index 09b6cf6adc008c3ba8eb05bb7093463b90be14b1..fa65e951d772b096ceda6ff631ea2a4b99f26070 100644 --- a/cpu/samd21/include/periph_cpu.h +++ b/cpu/samd21/include/periph_cpu.h @@ -79,6 +79,23 @@ typedef enum { GPIO_MUX_H = 0x7, /**< select peripheral function H */ } gpio_mux_t; +/** + * @brief PWM channel configuration data structure + */ +typedef struct { + gpio_t pin; /**< GPIO pin */ + gpio_mux_t mux; /**< pin function multiplex value */ + uint8_t chan; /**< TCC channel to use */ +} pwm_conf_chan_t; + +/** + * @brief PWM device configuration data structure + */ +typedef struct { + Tcc *dev; /*< TCC device to use */ + pwm_conf_chan_t chan[2]; /**< channel configuration */ +} pwm_conf_t; + /** * @brief UART device configuration */ diff --git a/cpu/samd21/periph/pwm.c b/cpu/samd21/periph/pwm.c index 6e6e23846ad7f22fd56f61adcb4fb6018f56f5bc..9260a2421defe759b31a68a938d76d5a99b6c240 100644 --- a/cpu/samd21/periph/pwm.c +++ b/cpu/samd21/periph/pwm.c @@ -26,8 +26,9 @@ #include "log.h" #include "cpu.h" #include "board.h" +#include "periph/gpio.h" #include "periph/pwm.h" -#include "periph_conf.h" + /* ignore file in case no PWM devices are defined */ #if PWM_NUMOF @@ -109,14 +110,8 @@ int pwm_init(pwm_t dev, pwm_mode_t mode, /* configure the used pins */ for (int i = 0; i < PWM_MAX_CHANNELS; i++) { - PortGroup *port = pwm_config[dev].chan[i].port; - int pin = pwm_config[dev].chan[i].pin; - int fnct = pwm_config[dev].chan[i].fnct; - /* set pin as output and enable the MUX */ - port->DIRSET.reg = (1 << pin); - port->PINCFG[pin].reg = (PORT_PINCFG_PMUXEN); - port->PMUX[pin >> 1].reg &= ~(0xf << (4 * (pin & 0x1))); - port->PMUX[pin >> 1].reg |= (fnct << (4 * (pin & 0x1))); + gpio_init(pwm_config[dev].chan[i].pin, GPIO_DIR_OUT, GPIO_NOPULL); + gpio_init_mux(pwm_config[dev].chan[i].pin, pwm_config[dev].chan[i].mux); } /* power on the device */