10
10
#include <zephyr/drivers/pwm.h>
11
11
#include <zephyr/dt-bindings/gpio/gpio.h>
12
12
#include <nrfx_gpiote.h>
13
- #include <nrfx_ppi .h>
13
+ #include <helpers/nrfx_gppi .h>
14
14
#include <hal/nrf_gpio.h>
15
15
#include <hal/nrf_rtc.h>
16
16
#include <hal/nrf_timer.h>
@@ -41,11 +41,17 @@ BUILD_ASSERT(DT_INST_PROP(0, clock_prescaler) == 0,
41
41
#error "Invalid number of PWM channels configured."
42
42
#endif
43
43
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
+
44
50
/* When RTC is used, one more PPI task endpoint is required for clearing
45
51
* the counter, so when FORK feature is not available, one more PPI channel
46
52
* needs to be used.
47
53
*/
48
- #if USE_RTC && !defined( PPI_FEATURE_FORKS_PRESENT )
54
+ #if USE_RTC && !PPI_FORK_AVAILABLE
49
55
#define PPI_PER_CH 3
50
56
#else
51
57
#define PPI_PER_CH 2
@@ -165,7 +171,7 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
165
171
/* clear PPI used */
166
172
ppi_mask = BIT (ppi_chs [0 ]) | BIT (ppi_chs [1 ]) |
167
173
(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 );
169
175
170
176
active_level = (flags & PWM_POLARITY_INVERTED ) ? 0 : 1 ;
171
177
@@ -265,15 +271,13 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
265
271
nrf_rtc_event_address_get (rtc ,
266
272
nrf_rtc_compare_event_get (0 ));
267
273
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 );
272
277
#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 );
277
281
#endif
278
282
} else {
279
283
pulse_end_event_address =
@@ -284,15 +288,13 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
284
288
nrf_timer_compare_event_get (0 ));
285
289
}
286
290
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 );
296
298
297
299
/* start timer, hence PWM */
298
300
if (USE_RTC ) {
@@ -347,7 +349,7 @@ static int pwm_nrf5_sw_init(const struct device *dev)
347
349
348
350
/* Allocate resources. */
349
351
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 ]);
351
353
if (err != NRFX_SUCCESS ) {
352
354
/* Do not free allocated resource. It is a fatal condition,
353
355
* system requires reconfiguration.
0 commit comments