diff --git a/boards/common/arduino-atmega/include/board_common.h b/boards/common/arduino-atmega/include/board_common.h index 9fa50998a5..efd5979291 100644 --- a/boards/common/arduino-atmega/include/board_common.h +++ b/boards/common/arduino-atmega/include/board_common.h @@ -123,18 +123,6 @@ extern "C" { #endif /** @} */ -/** - * @name Configuration parameters for the W5100 driver - * @{ - */ -#ifndef W5100_PARAM_CS -#define W5100_PARAM_CS (ARDUINO_PIN_10) -#endif -#ifndef W5100_PARAM_EVT -#define W5100_PARAM_EVT (ARDUINO_PIN_2) -#endif -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/common/arduino-due/include/board.h b/boards/common/arduino-due/include/board.h index a9b8903b7e..566069bef0 100644 --- a/boards/common/arduino-due/include/board.h +++ b/boards/common/arduino-due/include/board.h @@ -39,18 +39,6 @@ extern "C" { #define LED0_TOGGLE ((PIOB->PIO_ODSR & PIO_PB27) ? LED0_OFF : LED0_ON) /** @} */ -/** - * @name Configuration parameters for the W5100 driver - * @{ - */ -#ifndef W5100_PARAM_CS -#define W5100_PARAM_CS (ARDUINO_PIN_10) -#endif -#ifndef W5100_PARAM_EVT -#define W5100_PARAM_EVT (ARDUINO_PIN_2) -#endif -/** @} */ - #ifdef __cplusplus } #endif diff --git a/boards/nrf5340dk-app/Kconfig b/boards/nrf5340dk-app/Kconfig index 9ad84d1cbe..a5b742e0c0 100644 --- a/boards/nrf5340dk-app/Kconfig +++ b/boards/nrf5340dk-app/Kconfig @@ -11,6 +11,7 @@ config BOARD_NRF5340DK_APP bool default y select CPU_MODEL_NRF5340_APP + select HAS_PERIPH_PWM select HAS_PERIPH_RTT select HAS_PERIPH_TIMER select HAS_PERIPH_UART diff --git a/boards/nrf5340dk-app/Makefile.features b/boards/nrf5340dk-app/Makefile.features index cbbab49173..b4a32a3960 100644 --- a/boards/nrf5340dk-app/Makefile.features +++ b/boards/nrf5340dk-app/Makefile.features @@ -2,6 +2,7 @@ CPU_MODEL = nrf5340_app CPU = nrf53 # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtt FEATURES_PROVIDED += periph_timer FEATURES_PROVIDED += periph_uart diff --git a/boards/nrf5340dk-app/include/periph_conf.h b/boards/nrf5340dk-app/include/periph_conf.h index 6a673de319..a7ed356094 100644 --- a/boards/nrf5340dk-app/include/periph_conf.h +++ b/boards/nrf5340dk-app/include/periph_conf.h @@ -93,6 +93,25 @@ static const uart_conf_t uart_config[] = { #endif /** @} */ +/** + * @name PWM configuration + * @{ + */ +static const pwm_conf_t pwm_config[] = { + { + .dev = NRF_PWM0_S, + .pin = { + LED0_PIN, + LED1_PIN, + LED2_PIN, + LED3_PIN + } + }, +}; + +#define PWM_NUMOF ARRAY_SIZE(pwm_config) +/** @} */ + #ifdef __cplusplus } #endif diff --git a/boards/nrf9160dk/Kconfig b/boards/nrf9160dk/Kconfig index 09abc75c39..59be987652 100644 --- a/boards/nrf9160dk/Kconfig +++ b/boards/nrf9160dk/Kconfig @@ -12,6 +12,7 @@ config BOARD_NRF9160DK default y select CPU_MODEL_NRF9160 select HAS_PERIPH_I2C + select HAS_PERIPH_PWM select HAS_PERIPH_RTT select HAS_PERIPH_SPI select HAS_PERIPH_TIMER diff --git a/boards/nrf9160dk/Makefile.features b/boards/nrf9160dk/Makefile.features index 5fc79dc456..072cc8c92f 100644 --- a/boards/nrf9160dk/Makefile.features +++ b/boards/nrf9160dk/Makefile.features @@ -3,6 +3,7 @@ CPU = nrf9160 # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtt FEATURES_PROVIDED += periph_spi FEATURES_PROVIDED += periph_timer diff --git a/boards/nrf9160dk/include/periph_conf.h b/boards/nrf9160dk/include/periph_conf.h index 9ad5f1f4e3..9371c17889 100644 --- a/boards/nrf9160dk/include/periph_conf.h +++ b/boards/nrf9160dk/include/periph_conf.h @@ -116,7 +116,7 @@ static const uart_conf_t uart_config[] = { #define UART_0_ISR (isr_uarte0_spim0_spis0_twim0_twis0) /**< UART0_IRQ */ #define UART_1_ISR (isr_uarte1_spim1_spis1_twim1_twis1) /**< UART1_IRQ */ -#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART confgiguration NUMOF */ +#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART configuration NUMOF */ /** @} */ /** @@ -137,6 +137,25 @@ static const uart_conf_t uart_config[] = { #endif /** @} */ +/** + * @name PWM configuration + * @{ + */ +static const pwm_conf_t pwm_config[] = { + { + .dev = NRF_PWM0_S, + .pin = { + LED0_PIN, + LED1_PIN, + LED2_PIN, + LED3_PIN + } + }, +}; + +#define PWM_NUMOF ARRAY_SIZE(pwm_config) +/** @} */ + #ifdef __cplusplus } #endif diff --git a/cpu/nrf52/include/periph_cpu.h b/cpu/nrf52/include/periph_cpu.h index e9568fcc7c..81962e165c 100644 --- a/cpu/nrf52/include/periph_cpu.h +++ b/cpu/nrf52/include/periph_cpu.h @@ -153,54 +153,6 @@ typedef struct { #define i2c_pin_scl(dev) i2c_config[dev].scl /** @} */ -/** - * @name The PWM unit on the nRF52 supports 4 channels per device - */ -#define PWM_CHANNELS (4U) - -/** - * @name Generate PWM mode values - * - * To encode the PWM mode, we use two bit: - * - bit 0: select up or up-and-down counting - * - bit 15: select polarity - */ -#define PWM_MODE(ud, pol) (ud | (pol << 15)) - -/** - * @brief Override the PWM mode definitions - * @{ - */ -#define HAVE_PWM_MODE_T -typedef enum { - PWM_LEFT = PWM_MODE(0, 1), /**< left aligned PWM */ - PWM_RIGHT = PWM_MODE(0, 0), /**< right aligned PWM */ - PWM_CENTER = PWM_MODE(1, 1), /**< not supported */ - PWM_CENTER_INV = PWM_MODE(1, 0) /**< not supported */ -} pwm_mode_t; -/** @} */ - -/** - * @brief PWM configuration options - * - * Each device supports up to 4 channels. If you want to use less than 4 - * channels, just set the unused pins to GPIO_UNDEF. - * - * @note define unused pins only from right to left, so the defined channels - * always start with channel 0 to x and the undefined ones are from x+1 - * to PWM_CHANNELS. - * - * @warning All the channels not in active use must be set to GPIO_UNDEF; just - * initializing fewer members of pin would insert a 0 value, which - * would be interpreted as the P0.00 pin that's then driven. - */ -#if defined(PWM_PRESENT) || DOXYGEN -typedef struct { - NRF_PWM_Type *dev; /**< PWM device descriptor */ - gpio_t pin[PWM_CHANNELS]; /**< PWM out pins */ -} pwm_conf_t; -#endif - /** * @brief Size of the UART TX buffer for non-blocking mode. */ diff --git a/cpu/nrf53/include/periph_cpu.h b/cpu/nrf53/include/periph_cpu.h index 7dd0ab9974..46bd07ce58 100644 --- a/cpu/nrf53/include/periph_cpu.h +++ b/cpu/nrf53/include/periph_cpu.h @@ -26,6 +26,15 @@ extern "C" { #endif +/** + * @brief Peripheral clocks speed + */ +#define PERIPH_CLOCK_1MHZ MHZ(1) /**< 1MHz peripheral clock */ +#define PERIPH_CLOCK_16MHZ MHZ(16) /**< 16MHz peripheral clock */ +#define PERIPH_CLOCK_32MHZ MHZ(32) /**< 32MHz peripheral clock */ +#define PERIPH_CLOCK_64MHZ MHZ(64) /**< 64MHz peripheral clock */ +#define PERIPH_CLOCK PERIPH_CLOCK_16MHZ /**< For driver compatibility */ + #ifndef DOXYGEN /** * @brief Wrapper to fix differences between nRF families vendor files diff --git a/cpu/nrf5x_common/include/periph_cpu_common.h b/cpu/nrf5x_common/include/periph_cpu_common.h index b0a640ddbe..a909aa864f 100644 --- a/cpu/nrf5x_common/include/periph_cpu_common.h +++ b/cpu/nrf5x_common/include/periph_cpu_common.h @@ -312,6 +312,55 @@ typedef struct { */ #define USBDEV_CPU_DMA_REQUIREMENTS __attribute__((aligned(USBDEV_CPU_DMA_ALIGNMENT))) +#if !defined(CPU_FAM_NRF51) && !defined(DOXYGEN) +/** + * @brief The PWM unit on the nRF52, nRF53 and nRF9160 + * supports 4 channels per device + */ +#define PWM_CHANNELS (4U) + +/** + * @brief Generate PWM mode values + * + * To encode the PWM mode, we use two bit: + * - bit 0: select up or up-and-down counting + * - bit 15: select polarity + */ +#define PWM_MODE(ud, pol) (ud | (pol << 15)) + +/** + * @brief Override the PWM mode definitions + */ +#define HAVE_PWM_MODE_T +typedef enum { + PWM_LEFT = PWM_MODE(0, 1), /**< left aligned PWM */ + PWM_RIGHT = PWM_MODE(0, 0), /**< right aligned PWM */ + PWM_CENTER = PWM_MODE(1, 1), /**< not supported */ + PWM_CENTER_INV = PWM_MODE(1, 0) /**< not supported */ +} pwm_mode_t; + +/** + * @brief PWM configuration options + * + * Each device supports up to 4 channels. If you want to use less than 4 + * channels, just set the unused pins to GPIO_UNDEF. + * + * @note define unused pins only from right to left, so the defined channels + * always start with channel 0 to x and the undefined ones are from x+1 + * to PWM_CHANNELS. + * + * @warning All the channels not in active use must be set to GPIO_UNDEF; just + * initializing fewer members of pin would insert a 0 value, which + * would be interpreted as the P0.00 pin that's then driven. + */ +#if defined(PWM_PRESENT) +typedef struct { + NRF_PWM_Type *dev; /**< PWM device descriptor */ + gpio_t pin[PWM_CHANNELS]; /**< PWM out pins */ +} pwm_conf_t; +#endif +#endif /* ndef CPU_FAM_NRF51 */ + #ifdef __cplusplus } #endif diff --git a/cpu/nrf5x_common/periph/Makefile b/cpu/nrf5x_common/periph/Makefile index d297d3c679..cab8572513 100644 --- a/cpu/nrf5x_common/periph/Makefile +++ b/cpu/nrf5x_common/periph/Makefile @@ -7,6 +7,14 @@ ifneq (,$(filter periph_i2c,$(USEMODULE))) endif endif +# Select the specific implementation for `periph_pwm` +# nRF51 has its own PWM driver variant in its periph driver folder +ifneq (,$(filter periph_pwm,$(USEMODULE))) + ifneq (,$(filter $(CPU_FAM),nrf52 nrf53 nrf9160)) + SRC += pwm_nrfxx.c + endif +endif + # Select the specific implementation for `periph_spi` ifneq (,$(filter periph_spi,$(USEMODULE))) ifneq (,$(filter $(CPU_FAM),nrf52 nrf9160)) diff --git a/cpu/nrf52/periph/pwm.c b/cpu/nrf5x_common/periph/pwm_nrfxx.c similarity index 99% rename from cpu/nrf52/periph/pwm.c rename to cpu/nrf5x_common/periph/pwm_nrfxx.c index 798adb8499..5b766bb1e4 100644 --- a/cpu/nrf52/periph/pwm.c +++ b/cpu/nrf5x_common/periph/pwm_nrfxx.c @@ -7,7 +7,7 @@ */ /** - * @ingroup cpu_nrf52 + * @ingroup cpu_nrf5x_common * @{ * * @file diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 46b78b5cd7..437d53ae4d 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -180,6 +180,14 @@ ifneq (,$(filter servo_%,$(USEMODULE))) USEMODULE += servo endif +ifneq (,$(filter shield_w5100,$(USEMODULE))) + FEATURES_REQUIRED += arduino_pins + FEATURES_REQUIRED += arduino_shield_isp + FEATURES_REQUIRED += arduino_shield_uno + FEATURES_REQUIRED += arduino_spi + USEMODULE += w5100 +endif + ifneq (,$(filter sht1%,$(USEMODULE))) USEMODULE += sht1x endif diff --git a/drivers/doc.txt b/drivers/doc.txt index 5a90ad875b..981ef8d6cc 100644 --- a/drivers/doc.txt +++ b/drivers/doc.txt @@ -121,4 +121,32 @@ * @ingroup config * @brief Compile time configurations for different kinds of * devices that do not match any other category - */ \ No newline at end of file + */ + +/** + * @defgroup drivers_shield Shields - hardware extension daughter board drivers + * @ingroup drivers + * @brief Provides drivers for hardware extension daughter boards such as + * Arduino Shields + */ + +/** + * @defgroup drivers_shield_w5100 W5100 Ethernet Shield driver + * @ingroup drivers_shield + * @brief Driver for the Arduino W5100 Ethernet Shield + * + * Usage + * ===== + * + * The driver is enabled by using the module `shield_w5100`, e.g. with: + * + * ``` + * USEMODULE=shield_w5100 make BOARD=arduino-due -C examples/gnrc_networking + * ``` + * + * It depends on @ref drivers_w5100 and provides nothing more than the providing + * the correct configuration. For this, it depends on the `arduino_pins`, + * `arduino_spi`, `arduino_shield_uno` and the `arduino_shield_isp` feature. + * It should work out of the box for any fully Arduino UNO compatible board + * (including the ISP header) and correct I/O mapping (`arduino_*`) features. + */ diff --git a/drivers/servo/Kconfig b/drivers/servo/Kconfig index 744c7de1b5..21ce76e1d7 100644 --- a/drivers/servo/Kconfig +++ b/drivers/servo/Kconfig @@ -26,6 +26,7 @@ config MODULE_SERVO_PWM # PWM prescaler on nRF5x MCUs cannot generate a 50 Hz signal depends on !HAS_CPU_NRF51 depends on !HAS_CPU_NRF52 + depends on !HAS_CPU_NRF53 depends on !HAS_CPU_NRF9160 select MODULE_PERIPH_PWM select SERVO_DRIVER_BACKEND diff --git a/drivers/servo/Makefile.dep b/drivers/servo/Makefile.dep index 318c71dde8..e19816ce7e 100644 --- a/drivers/servo/Makefile.dep +++ b/drivers/servo/Makefile.dep @@ -5,7 +5,7 @@ endif # if no servo driver implementation is chosen, we pick one ifeq (,$(filter servo_pwm servo_timer,$(USEMODULE))) # choose servo_pwm except for MCUs known to be incompatible - ifneq (,$(filter nrf5%, $(CPU_FAM))) + ifneq (,$(filter nrf5% nrf9160, $(CPU_FAM))) USEMODULE += servo_timer else USEMODULE += servo_pwm diff --git a/drivers/w5100/include/w5100_params.h b/drivers/w5100/include/w5100_params.h index 30ebd3b2db..a7a7740cd3 100644 --- a/drivers/w5100/include/w5100_params.h +++ b/drivers/w5100/include/w5100_params.h @@ -21,10 +21,20 @@ #include "board.h" +#ifdef MODULE_SHIELD_W5100 +#include "arduino_iomap.h" +#endif + #ifdef __cplusplus extern "C" { #endif +#ifdef MODULE_SHIELD_W5100 +#define W5100_PARAM_SPI ARDUINO_SPI_ISP +#define W5100_PARAM_CS ARDUINO_PIN_10 +#define W5100_PARAM_EVT ARDUINO_PIN_2 +#endif + /** * @name Default configuration parameters for the W5100 driver * @{ diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 53455f549a..602281a02e 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -505,6 +505,7 @@ PSEUDOMODULES += shell_commands ## @} PSEUDOMODULES += shell_hooks PSEUDOMODULES += shell_lock_auto_locking +PSEUDOMODULES += shield_w5100 PSEUDOMODULES += slipdev_stdio PSEUDOMODULES += slipdev_l2addr PSEUDOMODULES += sock