Skip to content

Commit 37c6233

Browse files
bors[bot]maribudylad
authoredJul 10, 2023
Merge #19764 #19781
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]>
3 parents 123cce9 + f1ab3b1 + ef9dca0 commit 37c6233

File tree

19 files changed

+160
-76
lines changed

19 files changed

+160
-76
lines changed
 

‎boards/common/arduino-atmega/include/board_common.h

-12
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,6 @@ extern "C" {
123123
#endif
124124
/** @} */
125125

126-
/**
127-
* @name Configuration parameters for the W5100 driver
128-
* @{
129-
*/
130-
#ifndef W5100_PARAM_CS
131-
#define W5100_PARAM_CS (ARDUINO_PIN_10)
132-
#endif
133-
#ifndef W5100_PARAM_EVT
134-
#define W5100_PARAM_EVT (ARDUINO_PIN_2)
135-
#endif
136-
/** @} */
137-
138126
#ifdef __cplusplus
139127
}
140128
#endif

‎boards/common/arduino-due/include/board.h

-12
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@ extern "C" {
3939
#define LED0_TOGGLE ((PIOB->PIO_ODSR & PIO_PB27) ? LED0_OFF : LED0_ON)
4040
/** @} */
4141

42-
/**
43-
* @name Configuration parameters for the W5100 driver
44-
* @{
45-
*/
46-
#ifndef W5100_PARAM_CS
47-
#define W5100_PARAM_CS (ARDUINO_PIN_10)
48-
#endif
49-
#ifndef W5100_PARAM_EVT
50-
#define W5100_PARAM_EVT (ARDUINO_PIN_2)
51-
#endif
52-
/** @} */
53-
5442
#ifdef __cplusplus
5543
}
5644
#endif

‎boards/nrf5340dk-app/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ config BOARD_NRF5340DK_APP
1111
bool
1212
default y
1313
select CPU_MODEL_NRF5340_APP
14+
select HAS_PERIPH_PWM
1415
select HAS_PERIPH_RTT
1516
select HAS_PERIPH_TIMER
1617
select HAS_PERIPH_UART

‎boards/nrf5340dk-app/Makefile.features

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CPU_MODEL = nrf5340_app
22
CPU = nrf53
33

44
# Put defined MCU peripherals here (in alphabetical order)
5+
FEATURES_PROVIDED += periph_pwm
56
FEATURES_PROVIDED += periph_rtt
67
FEATURES_PROVIDED += periph_timer
78
FEATURES_PROVIDED += periph_uart

‎boards/nrf5340dk-app/include/periph_conf.h

+19
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ static const uart_conf_t uart_config[] = {
9393
#endif
9494
/** @} */
9595

96+
/**
97+
* @name PWM configuration
98+
* @{
99+
*/
100+
static const pwm_conf_t pwm_config[] = {
101+
{
102+
.dev = NRF_PWM0_S,
103+
.pin = {
104+
LED0_PIN,
105+
LED1_PIN,
106+
LED2_PIN,
107+
LED3_PIN
108+
}
109+
},
110+
};
111+
112+
#define PWM_NUMOF ARRAY_SIZE(pwm_config)
113+
/** @} */
114+
96115
#ifdef __cplusplus
97116
}
98117
#endif

‎boards/nrf9160dk/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ config BOARD_NRF9160DK
1212
default y
1313
select CPU_MODEL_NRF9160
1414
select HAS_PERIPH_I2C
15+
select HAS_PERIPH_PWM
1516
select HAS_PERIPH_RTT
1617
select HAS_PERIPH_SPI
1718
select HAS_PERIPH_TIMER

‎boards/nrf9160dk/Makefile.features

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CPU = nrf9160
33

44
# Put defined MCU peripherals here (in alphabetical order)
55
FEATURES_PROVIDED += periph_i2c
6+
FEATURES_PROVIDED += periph_pwm
67
FEATURES_PROVIDED += periph_rtt
78
FEATURES_PROVIDED += periph_spi
89
FEATURES_PROVIDED += periph_timer

‎boards/nrf9160dk/include/periph_conf.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static const uart_conf_t uart_config[] = {
116116
#define UART_0_ISR (isr_uarte0_spim0_spis0_twim0_twis0) /**< UART0_IRQ */
117117
#define UART_1_ISR (isr_uarte1_spim1_spis1_twim1_twis1) /**< UART1_IRQ */
118118

119-
#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART confgiguration NUMOF */
119+
#define UART_NUMOF ARRAY_SIZE(uart_config) /**< UART configuration NUMOF */
120120
/** @} */
121121

122122
/**
@@ -137,6 +137,25 @@ static const uart_conf_t uart_config[] = {
137137
#endif
138138
/** @} */
139139

140+
/**
141+
* @name PWM configuration
142+
* @{
143+
*/
144+
static const pwm_conf_t pwm_config[] = {
145+
{
146+
.dev = NRF_PWM0_S,
147+
.pin = {
148+
LED0_PIN,
149+
LED1_PIN,
150+
LED2_PIN,
151+
LED3_PIN
152+
}
153+
},
154+
};
155+
156+
#define PWM_NUMOF ARRAY_SIZE(pwm_config)
157+
/** @} */
158+
140159
#ifdef __cplusplus
141160
}
142161
#endif

‎cpu/nrf52/include/periph_cpu.h

-48
Original file line numberDiff line numberDiff line change
@@ -153,54 +153,6 @@ typedef struct {
153153
#define i2c_pin_scl(dev) i2c_config[dev].scl
154154
/** @} */
155155

156-
/**
157-
* @name The PWM unit on the nRF52 supports 4 channels per device
158-
*/
159-
#define PWM_CHANNELS (4U)
160-
161-
/**
162-
* @name Generate PWM mode values
163-
*
164-
* To encode the PWM mode, we use two bit:
165-
* - bit 0: select up or up-and-down counting
166-
* - bit 15: select polarity
167-
*/
168-
#define PWM_MODE(ud, pol) (ud | (pol << 15))
169-
170-
/**
171-
* @brief Override the PWM mode definitions
172-
* @{
173-
*/
174-
#define HAVE_PWM_MODE_T
175-
typedef enum {
176-
PWM_LEFT = PWM_MODE(0, 1), /**< left aligned PWM */
177-
PWM_RIGHT = PWM_MODE(0, 0), /**< right aligned PWM */
178-
PWM_CENTER = PWM_MODE(1, 1), /**< not supported */
179-
PWM_CENTER_INV = PWM_MODE(1, 0) /**< not supported */
180-
} pwm_mode_t;
181-
/** @} */
182-
183-
/**
184-
* @brief PWM configuration options
185-
*
186-
* Each device supports up to 4 channels. If you want to use less than 4
187-
* channels, just set the unused pins to GPIO_UNDEF.
188-
*
189-
* @note define unused pins only from right to left, so the defined channels
190-
* always start with channel 0 to x and the undefined ones are from x+1
191-
* to PWM_CHANNELS.
192-
*
193-
* @warning All the channels not in active use must be set to GPIO_UNDEF; just
194-
* initializing fewer members of pin would insert a 0 value, which
195-
* would be interpreted as the P0.00 pin that's then driven.
196-
*/
197-
#if defined(PWM_PRESENT) || DOXYGEN
198-
typedef struct {
199-
NRF_PWM_Type *dev; /**< PWM device descriptor */
200-
gpio_t pin[PWM_CHANNELS]; /**< PWM out pins */
201-
} pwm_conf_t;
202-
#endif
203-
204156
/**
205157
* @brief Size of the UART TX buffer for non-blocking mode.
206158
*/

‎cpu/nrf53/include/periph_cpu.h

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
extern "C" {
2727
#endif
2828

29+
/**
30+
* @brief Peripheral clocks speed
31+
*/
32+
#define PERIPH_CLOCK_1MHZ MHZ(1) /**< 1MHz peripheral clock */
33+
#define PERIPH_CLOCK_16MHZ MHZ(16) /**< 16MHz peripheral clock */
34+
#define PERIPH_CLOCK_32MHZ MHZ(32) /**< 32MHz peripheral clock */
35+
#define PERIPH_CLOCK_64MHZ MHZ(64) /**< 64MHz peripheral clock */
36+
#define PERIPH_CLOCK PERIPH_CLOCK_16MHZ /**< For driver compatibility */
37+
2938
#ifndef DOXYGEN
3039
/**
3140
* @brief Wrapper to fix differences between nRF families vendor files

‎cpu/nrf5x_common/include/periph_cpu_common.h

+49
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,55 @@ typedef struct {
312312
*/
313313
#define USBDEV_CPU_DMA_REQUIREMENTS __attribute__((aligned(USBDEV_CPU_DMA_ALIGNMENT)))
314314

315+
#if !defined(CPU_FAM_NRF51) && !defined(DOXYGEN)
316+
/**
317+
* @brief The PWM unit on the nRF52, nRF53 and nRF9160
318+
* supports 4 channels per device
319+
*/
320+
#define PWM_CHANNELS (4U)
321+
322+
/**
323+
* @brief Generate PWM mode values
324+
*
325+
* To encode the PWM mode, we use two bit:
326+
* - bit 0: select up or up-and-down counting
327+
* - bit 15: select polarity
328+
*/
329+
#define PWM_MODE(ud, pol) (ud | (pol << 15))
330+
331+
/**
332+
* @brief Override the PWM mode definitions
333+
*/
334+
#define HAVE_PWM_MODE_T
335+
typedef enum {
336+
PWM_LEFT = PWM_MODE(0, 1), /**< left aligned PWM */
337+
PWM_RIGHT = PWM_MODE(0, 0), /**< right aligned PWM */
338+
PWM_CENTER = PWM_MODE(1, 1), /**< not supported */
339+
PWM_CENTER_INV = PWM_MODE(1, 0) /**< not supported */
340+
} pwm_mode_t;
341+
342+
/**
343+
* @brief PWM configuration options
344+
*
345+
* Each device supports up to 4 channels. If you want to use less than 4
346+
* channels, just set the unused pins to GPIO_UNDEF.
347+
*
348+
* @note define unused pins only from right to left, so the defined channels
349+
* always start with channel 0 to x and the undefined ones are from x+1
350+
* to PWM_CHANNELS.
351+
*
352+
* @warning All the channels not in active use must be set to GPIO_UNDEF; just
353+
* initializing fewer members of pin would insert a 0 value, which
354+
* would be interpreted as the P0.00 pin that's then driven.
355+
*/
356+
#if defined(PWM_PRESENT)
357+
typedef struct {
358+
NRF_PWM_Type *dev; /**< PWM device descriptor */
359+
gpio_t pin[PWM_CHANNELS]; /**< PWM out pins */
360+
} pwm_conf_t;
361+
#endif
362+
#endif /* ndef CPU_FAM_NRF51 */
363+
315364
#ifdef __cplusplus
316365
}
317366
#endif

‎cpu/nrf5x_common/periph/Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ ifneq (,$(filter periph_i2c,$(USEMODULE)))
77
endif
88
endif
99

10+
# Select the specific implementation for `periph_pwm`
11+
# nRF51 has its own PWM driver variant in its periph driver folder
12+
ifneq (,$(filter periph_pwm,$(USEMODULE)))
13+
ifneq (,$(filter $(CPU_FAM),nrf52 nrf53 nrf9160))
14+
SRC += pwm_nrfxx.c
15+
endif
16+
endif
17+
1018
# Select the specific implementation for `periph_spi`
1119
ifneq (,$(filter periph_spi,$(USEMODULE)))
1220
ifneq (,$(filter $(CPU_FAM),nrf52 nrf9160))

‎cpu/nrf52/periph/pwm.c ‎cpu/nrf5x_common/periph/pwm_nrfxx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
/**
10-
* @ingroup cpu_nrf52
10+
* @ingroup cpu_nrf5x_common
1111
* @{
1212
*
1313
* @file

‎drivers/Makefile.dep

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ ifneq (,$(filter servo_%,$(USEMODULE)))
180180
USEMODULE += servo
181181
endif
182182

183+
ifneq (,$(filter shield_w5100,$(USEMODULE)))
184+
FEATURES_REQUIRED += arduino_pins
185+
FEATURES_REQUIRED += arduino_shield_isp
186+
FEATURES_REQUIRED += arduino_shield_uno
187+
FEATURES_REQUIRED += arduino_spi
188+
USEMODULE += w5100
189+
endif
190+
183191
ifneq (,$(filter sht1%,$(USEMODULE)))
184192
USEMODULE += sht1x
185193
endif

‎drivers/doc.txt

+29-1
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,32 @@
121121
* @ingroup config
122122
* @brief Compile time configurations for different kinds of
123123
* devices that do not match any other category
124-
*/
124+
*/
125+
126+
/**
127+
* @defgroup drivers_shield Shields - hardware extension daughter board drivers
128+
* @ingroup drivers
129+
* @brief Provides drivers for hardware extension daughter boards such as
130+
* Arduino Shields
131+
*/
132+
133+
/**
134+
* @defgroup drivers_shield_w5100 W5100 Ethernet Shield driver
135+
* @ingroup drivers_shield
136+
* @brief Driver for the Arduino W5100 Ethernet Shield
137+
*
138+
* Usage
139+
* =====
140+
*
141+
* The driver is enabled by using the module `shield_w5100`, e.g. with:
142+
*
143+
* ```
144+
* USEMODULE=shield_w5100 make BOARD=arduino-due -C examples/gnrc_networking
145+
* ```
146+
*
147+
* It depends on @ref drivers_w5100 and provides nothing more than the providing
148+
* the correct configuration. For this, it depends on the `arduino_pins`,
149+
* `arduino_spi`, `arduino_shield_uno` and the `arduino_shield_isp` feature.
150+
* It should work out of the box for any fully Arduino UNO compatible board
151+
* (including the ISP header) and correct I/O mapping (`arduino_*`) features.
152+
*/

‎drivers/servo/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config MODULE_SERVO_PWM
2626
# PWM prescaler on nRF5x MCUs cannot generate a 50 Hz signal
2727
depends on !HAS_CPU_NRF51
2828
depends on !HAS_CPU_NRF52
29+
depends on !HAS_CPU_NRF53
2930
depends on !HAS_CPU_NRF9160
3031
select MODULE_PERIPH_PWM
3132
select SERVO_DRIVER_BACKEND

‎drivers/servo/Makefile.dep

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ endif
55
# if no servo driver implementation is chosen, we pick one
66
ifeq (,$(filter servo_pwm servo_timer,$(USEMODULE)))
77
# choose servo_pwm except for MCUs known to be incompatible
8-
ifneq (,$(filter nrf5%, $(CPU_FAM)))
8+
ifneq (,$(filter nrf5% nrf9160, $(CPU_FAM)))
99
USEMODULE += servo_timer
1010
else
1111
USEMODULE += servo_pwm

‎drivers/w5100/include/w5100_params.h

+10
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@
2121

2222
#include "board.h"
2323

24+
#ifdef MODULE_SHIELD_W5100
25+
#include "arduino_iomap.h"
26+
#endif
27+
2428
#ifdef __cplusplus
2529
extern "C" {
2630
#endif
2731

32+
#ifdef MODULE_SHIELD_W5100
33+
#define W5100_PARAM_SPI ARDUINO_SPI_ISP
34+
#define W5100_PARAM_CS ARDUINO_PIN_10
35+
#define W5100_PARAM_EVT ARDUINO_PIN_2
36+
#endif
37+
2838
/**
2939
* @name Default configuration parameters for the W5100 driver
3040
* @{

‎makefiles/pseudomodules.inc.mk

+1
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ PSEUDOMODULES += shell_commands
505505
## @}
506506
PSEUDOMODULES += shell_hooks
507507
PSEUDOMODULES += shell_lock_auto_locking
508+
PSEUDOMODULES += shield_w5100
508509
PSEUDOMODULES += slipdev_stdio
509510
PSEUDOMODULES += slipdev_l2addr
510511
PSEUDOMODULES += sock

0 commit comments

Comments
 (0)
Please sign in to comment.