Skip to content

Commit 9e86006

Browse files
ananglcarlescufi
authored andcommitted
drivers: pwm_nrf5_sw: Use GPIOTE SET and CLR tasks when available
When possible, use separate GPIOTE tasks for setting the PWM output high and low instead of using one task to toggle it. This is crucial for DPPI where the same task cannot be used in more than one channel. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent c43cef0 commit 9e86006

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

drivers/pwm/pwm_nrf5_sw.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,23 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
237237

238238
/* setup PPI */
239239
uint32_t pulse_end_event_address, period_end_event_address;
240-
uint32_t gpiote_out_task_address =
241-
nrf_gpiote_task_address_get(NRF_GPIOTE,
242-
nrf_gpiote_out_task_get(gpiote_ch));
240+
nrf_gpiote_task_t pulse_end_task, period_end_task;
241+
#if defined(GPIOTE_FEATURE_SET_PRESENT) && defined(GPIOTE_FEATURE_CLR_PRESENT)
242+
if (active_level == 0) {
243+
pulse_end_task = nrf_gpiote_set_task_get(gpiote_ch);
244+
period_end_task = nrf_gpiote_clr_task_get(gpiote_ch);
245+
} else {
246+
pulse_end_task = nrf_gpiote_clr_task_get(gpiote_ch);
247+
period_end_task = nrf_gpiote_set_task_get(gpiote_ch);
248+
}
249+
#else
250+
pulse_end_task = period_end_task = nrf_gpiote_out_task_get(gpiote_ch);
251+
#endif
252+
uint32_t pulse_end_task_address =
253+
nrf_gpiote_task_address_get(NRF_GPIOTE, pulse_end_task);
254+
uint32_t period_end_task_address =
255+
nrf_gpiote_task_address_get(NRF_GPIOTE, period_end_task);
256+
243257
if (USE_RTC) {
244258
uint32_t clear_task_address =
245259
nrf_rtc_event_address_get(rtc, NRF_RTC_TASK_CLEAR);
@@ -273,11 +287,11 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
273287
nrf_ppi_channel_endpoint_setup(NRF_PPI,
274288
ppi_chs[0],
275289
pulse_end_event_address,
276-
gpiote_out_task_address);
290+
pulse_end_task_address);
277291
nrf_ppi_channel_endpoint_setup(NRF_PPI,
278292
ppi_chs[1],
279293
period_end_event_address,
280-
gpiote_out_task_address);
294+
period_end_task_address);
281295
nrf_ppi_channels_enable(NRF_PPI, ppi_mask);
282296

283297
/* start timer, hence PWM */

0 commit comments

Comments
 (0)