diff --git a/boards/common/arduino-atmega/Makefile.features b/boards/common/arduino-atmega/Makefile.features index 3786b2a318..ec1f08f176 100644 --- a/boards/common/arduino-atmega/Makefile.features +++ b/boards/common/arduino-atmega/Makefile.features @@ -9,6 +9,7 @@ FEATURES_PROVIDED += periph_uart # Various other features (if any) ifeq (,$(filter jiminy-mega256rfr2,$(BOARD))) FEATURES_PROVIDED += arduino + FEATURES_PROVIDED += periph_pwm endif # The board MPU family (used for grouping by the CI system) diff --git a/boards/common/arduino-atmega/include/periph_conf.h b/boards/common/arduino-atmega/include/periph_conf.h index 5a8a026a18..a73f794b25 100644 --- a/boards/common/arduino-atmega/include/periph_conf.h +++ b/boards/common/arduino-atmega/include/periph_conf.h @@ -24,6 +24,8 @@ #ifndef PERIPH_CONF_H #define PERIPH_CONF_H +#include "periph_cpu.h" + #ifdef __cplusplus extern "C" { #endif @@ -163,6 +165,46 @@ extern "C" { #endif /** @} */ +/** + * @name PWM configuration + * + * The current implementation supports only 8-bit timers for PWM generation. + * These timers are typically timer 0 and timer 2 in Atmega2560/1281/328p. + * + * Setting the first channel to GPIO_UNDEF allows multiple resolutions for the + * PWM channel. Otherwise the resolution is fixed to 256, allowing duty cycle + * values ranging from 0 to 255. + * + * @{ + */ +#if defined(CPU_ATMEGA328P) +#define PWM_PINS_CH0 { GPIO_PIN(PORT_D, 6), GPIO_PIN(PORT_D, 5) } +#define PWM_PINS_CH1 { GPIO_PIN(PORT_B, 3), GPIO_PIN(PORT_D, 3) } + +#elif defined(CPU_ATMEGA2560) +#define PWM_PINS_CH0 { GPIO_PIN(PORT_B, 7), GPIO_PIN(PORT_G, 5) } +#define PWM_PINS_CH1 { GPIO_PIN(PORT_B, 4), GPIO_PIN(PORT_H, 6) } + +#elif defined(CPU_ATMEGA1281) +#define PWM_PINS_CH0 { GPIO_PIN(PORT_B, 7), GPIO_PIN(PORT_G, 5) } +#define PWM_PINS_CH1 { GPIO_PIN(PORT_B, 4), GPIO_UNDEF } +#endif + +static const pwm_conf_t pwm_conf[] = { + { + .dev = MINI_TIMER0, + .pin_ch = PWM_PINS_CH0, + .div = MINI_TIMER0_DIV, + }, + { + .dev = MINI_TIMER2, + .pin_ch = PWM_PINS_CH1, + .div = MINI_TIMER2_DIV, + } +}; +#define PWM_NUMOF (sizeof(pwm_conf) / sizeof(pwm_conf[0])) +/** @} */ + #ifdef __cplusplus } #endif diff --git a/tests/periph_pwm/Makefile b/tests/periph_pwm/Makefile index ab079f2f72..7485834066 100644 --- a/tests/periph_pwm/Makefile +++ b/tests/periph_pwm/Makefile @@ -1,6 +1,8 @@ BOARD ?= samr21-xpro include ../Makefile.tests_common +BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-uno + FEATURES_REQUIRED = periph_pwm USEMODULE += xtimer