Skip to content

Commit 8c1c666

Browse files
ananglcarlescufi
authored andcommitted
drivers: pwm_nrf5_sw: Extend to work also with DPPI
Instead of directly configuring PPI channels, use the GPPI helper provided by nrfx. This allows using the driver on nRF53 an nRF91 Series where DPPI is available instead of PPI. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 9e86006 commit 8c1c666

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

drivers/pwm/Kconfig.nrf5_sw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ config PWM_NRF5_SW
77
bool "Nordic Semiconductor nRF5x series S/W PWM"
88
default y if !PWM_NRFX
99
depends on DT_HAS_NORDIC_NRF_SW_PWM_ENABLED
10-
depends on DT_HAS_NORDIC_NRF_PPI_ENABLED
1110
select NRFX_GPIOTE
12-
select NRFX_PPI
11+
select NRFX_PPI if HAS_HW_NRF_PPI
12+
select NRFX_DPPI if HAS_HW_NRF_DPPIC
1313
help
1414
Enable driver to utilize PWM on the Nordic Semiconductor nRF5x series.
1515

drivers/pwm/pwm_nrf5_sw.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <zephyr/drivers/pwm.h>
1111
#include <zephyr/dt-bindings/gpio/gpio.h>
1212
#include <nrfx_gpiote.h>
13-
#include <nrfx_ppi.h>
13+
#include <helpers/nrfx_gppi.h>
1414
#include <hal/nrf_gpio.h>
1515
#include <hal/nrf_rtc.h>
1616
#include <hal/nrf_timer.h>
@@ -41,11 +41,17 @@ BUILD_ASSERT(DT_INST_PROP(0, clock_prescaler) == 0,
4141
#error "Invalid number of PWM channels configured."
4242
#endif
4343

44+
#if defined(PPI_FEATURE_FORKS_PRESENT) || defined(DPPI_PRESENT)
45+
#define PPI_FORK_AVAILABLE 1
46+
#else
47+
#define PPI_FORK_AVAILABLE 0
48+
#endif
49+
4450
/* When RTC is used, one more PPI task endpoint is required for clearing
4551
* the counter, so when FORK feature is not available, one more PPI channel
4652
* needs to be used.
4753
*/
48-
#if USE_RTC && !defined(PPI_FEATURE_FORKS_PRESENT)
54+
#if USE_RTC && !PPI_FORK_AVAILABLE
4955
#define PPI_PER_CH 3
5056
#else
5157
#define PPI_PER_CH 2
@@ -165,7 +171,7 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
165171
/* clear PPI used */
166172
ppi_mask = BIT(ppi_chs[0]) | BIT(ppi_chs[1]) |
167173
(PPI_PER_CH > 2 ? BIT(ppi_chs[2]) : 0);
168-
nrf_ppi_channels_disable(NRF_PPI, ppi_mask);
174+
nrfx_gppi_channels_disable(ppi_mask);
169175

170176
active_level = (flags & PWM_POLARITY_INVERTED) ? 0 : 1;
171177

@@ -265,15 +271,13 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
265271
nrf_rtc_event_address_get(rtc,
266272
nrf_rtc_compare_event_get(0));
267273

268-
#if defined(PPI_FEATURE_FORKS_PRESENT)
269-
nrf_ppi_fork_endpoint_setup(NRF_PPI,
270-
ppi_chs[1],
271-
clear_task_address);
274+
#if PPI_FORK_AVAILABLE
275+
nrfx_gppi_fork_endpoint_setup(ppi_chs[1],
276+
clear_task_addr);
272277
#else
273-
nrf_ppi_channel_endpoint_setup(NRF_PPI,
274-
ppi_chs[2],
275-
period_end_event_address,
276-
clear_task_address);
278+
nrfx_gppi_channel_endpoints_setup(ppi_chs[2],
279+
period_end_event_address,
280+
clear_task_address);
277281
#endif
278282
} else {
279283
pulse_end_event_address =
@@ -284,15 +288,13 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
284288
nrf_timer_compare_event_get(0));
285289
}
286290

287-
nrf_ppi_channel_endpoint_setup(NRF_PPI,
288-
ppi_chs[0],
289-
pulse_end_event_address,
290-
pulse_end_task_address);
291-
nrf_ppi_channel_endpoint_setup(NRF_PPI,
292-
ppi_chs[1],
293-
period_end_event_address,
294-
period_end_task_address);
295-
nrf_ppi_channels_enable(NRF_PPI, ppi_mask);
291+
nrfx_gppi_channel_endpoints_setup(ppi_chs[0],
292+
pulse_end_event_address,
293+
pulse_end_task_address);
294+
nrfx_gppi_channel_endpoints_setup(ppi_chs[1],
295+
period_end_event_address,
296+
period_end_task_address);
297+
nrfx_gppi_channels_enable(ppi_mask);
296298

297299
/* start timer, hence PWM */
298300
if (USE_RTC) {
@@ -347,7 +349,7 @@ static int pwm_nrf5_sw_init(const struct device *dev)
347349

348350
/* Allocate resources. */
349351
for (uint32_t j = 0; j < PPI_PER_CH; j++) {
350-
err = nrfx_ppi_channel_alloc(&data->ppi_ch[i][j]);
352+
err = nrfx_gppi_channel_alloc(&data->ppi_ch[i][j]);
351353
if (err != NRFX_SUCCESS) {
352354
/* Do not free allocated resource. It is a fatal condition,
353355
* system requires reconfiguration.

0 commit comments

Comments
 (0)