From 85c2f43415998f9df710db13ba14d8c74a4d8665 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 25 Jun 2023 21:04:32 +0200 Subject: [PATCH 1/7] boards: Remove W5100 configuration Rather than providing this for every board (or group of boards) individually, it is better to provide this once relying on the Arduino I/O mapping features. --- boards/common/arduino-atmega/include/board_common.h | 12 ------------ boards/common/arduino-due/include/board.h | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/boards/common/arduino-atmega/include/board_common.h b/boards/common/arduino-atmega/include/board_common.h index 9fa50998a5b7..efd597929136 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 a9b8903b7e8a..566069bef036 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 From f1ab3b1ea674de63663560a19eaaad205a212a9b Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 25 Jun 2023 21:05:50 +0200 Subject: [PATCH 2/7] drivers/shield_w5100: add module for the W5100 Ethernet Shield This module provides no more than the correct configuration parameters for the `w5100` driver using the Arduino I/O mapping features. But by doing so, it will work out of the box with every mechanically and electrically compatible board for which the Arduino I/O mapping features are implemented. --- drivers/Makefile.dep | 8 ++++++++ drivers/doc.txt | 30 +++++++++++++++++++++++++++- drivers/w5100/include/w5100_params.h | 10 ++++++++++ makefiles/pseudomodules.inc.mk | 1 + 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 9be99ff67e82..f3ef3486f83f 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 5a90ad875b1c..981ef8d6cceb 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/w5100/include/w5100_params.h b/drivers/w5100/include/w5100_params.h index 30ebd3b2dbfc..a7a7740cd310 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 8d0ecdb50403..9c824ae899f2 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -494,6 +494,7 @@ PSEUDOMODULES += shell_commands ## @} PSEUDOMODULES += shell_hooks PSEUDOMODULES += shell_lock_auto_locking +PSEUDOMODULES += shield_w5100 PSEUDOMODULES += slipdev_stdio PSEUDOMODULES += slipdev_l2addr PSEUDOMODULES += sock From 6ea5081da9f6a830a27ed902565a4c45105f8651 Mon Sep 17 00:00:00 2001 From: Dylan Laduranty Date: Fri, 7 Jul 2023 09:07:15 +0200 Subject: [PATCH 3/7] cpu/nrf5x_common: share nRF52 PWM driver with nRF53/nRF9160 Signed-off-by: Dylan Laduranty --- cpu/nrf52/include/periph_cpu.h | 48 ------------------ cpu/nrf5x_common/include/periph_cpu_common.h | 49 +++++++++++++++++++ cpu/nrf5x_common/periph/Makefile | 8 +++ .../pwm.c => nrf5x_common/periph/pwm_nrfxx.c} | 2 +- 4 files changed, 58 insertions(+), 49 deletions(-) rename cpu/{nrf52/periph/pwm.c => nrf5x_common/periph/pwm_nrfxx.c} (99%) diff --git a/cpu/nrf52/include/periph_cpu.h b/cpu/nrf52/include/periph_cpu.h index e9568fcc7c86..81962e165c9d 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/nrf5x_common/include/periph_cpu_common.h b/cpu/nrf5x_common/include/periph_cpu_common.h index b0a640ddbe1a..a909aa864f7e 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 d297d3c6790f..cab857251381 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 798adb8499d3..5b766bb1e418 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 From 2033911b7f067d5fa84ee3ab8524f88cea87c46a Mon Sep 17 00:00:00 2001 From: Dylan Laduranty Date: Fri, 7 Jul 2023 09:07:52 +0200 Subject: [PATCH 4/7] cpu/nrf53: introduce peripheral clocks defines Signed-off-by: Dylan Laduranty --- cpu/nrf53/include/periph_cpu.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cpu/nrf53/include/periph_cpu.h b/cpu/nrf53/include/periph_cpu.h index 7dd0ab9974a9..46bd07ce5873 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 From aeff14703b762debadf1eea85875af0061d9221b Mon Sep 17 00:00:00 2001 From: Dylan Laduranty Date: Fri, 7 Jul 2023 09:08:12 +0200 Subject: [PATCH 5/7] boards/nrf5340dk-app: enable PWM support on onboard LEDs Signed-off-by: Dylan Laduranty --- boards/nrf5340dk-app/Kconfig | 1 + boards/nrf5340dk-app/Makefile.features | 1 + boards/nrf5340dk-app/include/periph_conf.h | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/boards/nrf5340dk-app/Kconfig b/boards/nrf5340dk-app/Kconfig index 9ad84d1cbe7a..a5b742e0c011 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 cbbab491735d..b4a32a3960f9 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 6a673de319ed..a7ed35609448 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 From 328d84fcf1ce89c3bb7495e523ce6dcf9cab7ee9 Mon Sep 17 00:00:00 2001 From: Dylan Laduranty Date: Fri, 7 Jul 2023 09:08:30 +0200 Subject: [PATCH 6/7] boards/nrf9160dk: enable PWM support on onboard LEDs Signed-off-by: Dylan Laduranty --- boards/nrf9160dk/Kconfig | 1 + boards/nrf9160dk/Makefile.features | 1 + boards/nrf9160dk/include/periph_conf.h | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/boards/nrf9160dk/Kconfig b/boards/nrf9160dk/Kconfig index 09abc75c3920..59be987652bc 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 5fc79dc45640..072cc8c92fad 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 9ad5f1f4e389..9371c1788992 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 From ef9dca01081e308ff9bae26fc4f7fafc3238f6cc Mon Sep 17 00:00:00 2001 From: dylad Date: Sat, 8 Jul 2023 16:50:30 +0200 Subject: [PATCH 7/7] drivers/servo: update build dependencies for Nordic families Signed-off-by: dylad --- drivers/servo/Kconfig | 1 + drivers/servo/Makefile.dep | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/servo/Kconfig b/drivers/servo/Kconfig index 744c7de1b546..21ce76e1d7de 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 318c71dde80b..e19816ce7e85 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