Skip to content

Commit

Permalink
Merge #19764 #19781
Browse files Browse the repository at this point in the history
19764: drivers/shield_w5100: add module for the W5100 Ethernet Shield r=benpicco a=maribu

### Contribution description

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.


19781: cpu/nrf{53,9160}: add pwm support r=benpicco a=dylad

### Contribution description

This PR moves the nRF52 PWM driver to `cpu/nrf5x_common` to allow nRF9160 and nRF53 to use this driver.
IP is identical on these families.

I didn't test on nRF9160DK and I didn't test if there is any regression on nRF52-based board as I don't have any so tests are welcome !
However it works fine on nRF53-based board.


### Testing procedure

Flash the `tests/periph/pwm` test application on `nrf5340dk` or `nrf9160dk`.
You can then use the `osci` command to make the onboard LEDs "breath".
You can also attach an oscilloscope and/or logic analyzer to watch the signal.


### Issues/PRs references
~~Based on #19769~~

Co-authored-by: Marian Buschsieweke <[email protected]>
Co-authored-by: Dylan Laduranty <[email protected]>
Co-authored-by: dylad <[email protected]>
  • Loading branch information
3 people authored Jul 10, 2023
3 parents 123cce9 + f1ab3b1 + ef9dca0 commit 37c6233
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 76 deletions.
12 changes: 0 additions & 12 deletions boards/common/arduino-atmega/include/board_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions boards/common/arduino-due/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions boards/nrf5340dk-app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions boards/nrf5340dk-app/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions boards/nrf5340dk-app/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions boards/nrf9160dk/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions boards/nrf9160dk/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion boards/nrf9160dk/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/** @} */

/**
Expand All @@ -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
Expand Down
48 changes: 0 additions & 48 deletions cpu/nrf52/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
9 changes: 9 additions & 0 deletions cpu/nrf53/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions cpu/nrf5x_common/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions cpu/nrf5x_common/periph/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/**
* @ingroup cpu_nrf52
* @ingroup cpu_nrf5x_common
* @{
*
* @file
Expand Down
8 changes: 8 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion drivers/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,32 @@
* @ingroup config
* @brief Compile time configurations for different kinds of
* devices that do not match any other category
*/
*/

/**
* @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.
*/
1 change: 1 addition & 0 deletions drivers/servo/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion drivers/servo/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions drivers/w5100/include/w5100_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @{
Expand Down
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37c6233

Please sign in to comment.