@@ -72,8 +72,9 @@ struct pwm_config {
7272struct pwm_data {
7373 uint32_t period_cycles ;
7474 uint32_t pulse_cycles [PWM_0_MAP_SIZE ];
75- uint8_t ppi_ch [PWM_0_MAP_SIZE ][PPI_PER_CH ];
75+ nrfx_gppi_handle_t ppi_h [PWM_0_MAP_SIZE ][PPI_PER_CH ];
7676 uint8_t gpiote_ch [PWM_0_MAP_SIZE ];
77+ uint32_t ppi_ch_mask [PWM_0_MAP_SIZE ];
7778};
7879
7980static inline NRF_RTC_Type * pwm_config_rtc (const struct pwm_config * config )
@@ -126,11 +127,11 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel,
126127 NRF_RTC_Type * rtc = pwm_config_rtc (config );
127128 NRF_GPIOTE_Type * gpiote ;
128129 struct pwm_data * data = dev -> data ;
129- uint32_t ppi_mask ;
130130 uint8_t active_level ;
131131 uint8_t psel_ch ;
132132 uint8_t gpiote_ch ;
133- const uint8_t * ppi_chs ;
133+ const nrfx_gppi_handle_t * ppi_chs ;
134+ uint32_t src_d = nrfx_gppi_domain_id_get ((USE_RTC ? (uint32_t )rtc : (uint32_t )timer ));
134135 int ret ;
135136
136137 if (channel >= config -> map_size ) {
@@ -166,15 +167,13 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel,
166167 gpiote = config -> gpiote [channel ].p_reg ;
167168 psel_ch = config -> psel_ch [channel ];
168169 gpiote_ch = data -> gpiote_ch [channel ];
169- ppi_chs = data -> ppi_ch [channel ];
170+ ppi_chs = data -> ppi_h [channel ];
170171
171172 LOG_DBG ("channel %u, period %u, pulse %u" ,
172173 channel , period_cycles , pulse_cycles );
173174
174- /* clear PPI used */
175- ppi_mask = BIT (ppi_chs [0 ]) | BIT (ppi_chs [1 ]) |
176- (PPI_PER_CH > 2 ? BIT (ppi_chs [2 ]) : 0 );
177- nrfx_gppi_channels_disable (ppi_mask );
175+ /* disable PPI used */
176+ nrfx_gppi_channels_disable (src_d , data -> ppi_ch_mask [channel ]);
178177
179178 active_level = (flags & PWM_POLARITY_INVERTED ) ? 0 : 1 ;
180179
@@ -278,12 +277,10 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel,
278277 nrf_rtc_compare_event_get (0 ));
279278
280279#if PPI_FORK_AVAILABLE
281- nrfx_gppi_fork_endpoint_setup (ppi_chs [1 ],
282- clear_task_address );
280+ nrfx_gppi_ep_attach (ppi_chs [1 ], clear_task_address );
283281#else
284- nrfx_gppi_channel_endpoints_setup (ppi_chs [2 ],
285- period_end_event_address ,
286- clear_task_address );
282+ nrfx_gppi_ep_attach (ppi_chs [2 ], period_end_event_address );
283+ nrfx_gppi_ep_attach (ppi_chs [2 ], clear_task_address );
287284#endif
288285 } else {
289286 pulse_end_event_address =
@@ -294,13 +291,13 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel,
294291 nrf_timer_compare_event_get (0 ));
295292 }
296293
297- nrfx_gppi_channel_endpoints_setup (ppi_chs [0 ],
298- pulse_end_event_address ,
299- pulse_end_task_address );
300- nrfx_gppi_channel_endpoints_setup (ppi_chs [1 ],
301- period_end_event_address ,
302- period_end_task_address );
303- nrfx_gppi_channels_enable (ppi_mask );
294+ nrfx_gppi_ep_attach (ppi_chs [0 ], pulse_end_event_address );
295+ nrfx_gppi_ep_attach ( ppi_chs [ 0 ], pulse_end_task_address );
296+
297+ nrfx_gppi_ep_attach (ppi_chs [1 ], period_end_event_address );
298+ nrfx_gppi_ep_attach ( ppi_chs [ 1 ], period_end_task_address );
299+
300+ nrfx_gppi_channels_enable (src_d , data -> ppi_ch_mask [ channel ] );
304301
305302 /* start timer, hence PWM */
306303 if (USE_RTC ) {
@@ -349,21 +346,32 @@ static int pwm_nrf_sw_init(const struct device *dev)
349346 struct pwm_data * data = dev -> data ;
350347 NRF_TIMER_Type * timer = pwm_config_timer (config );
351348 NRF_RTC_Type * rtc = pwm_config_rtc (config );
349+ uint32_t src_d = nrfx_gppi_domain_id_get ((USE_RTC ? (uint32_t )rtc : (uint32_t )timer ));
352350
353351 for (uint32_t i = 0 ; i < config -> map_size ; i ++ ) {
354352 nrfx_err_t err ;
353+ uint32_t dst_d = nrfx_gppi_domain_id_get ((uint32_t )config -> gpiote [i ].p_reg );
354+ int rv ;
355355
356356 /* Allocate resources. */
357357 for (uint32_t j = 0 ; j < PPI_PER_CH ; j ++ ) {
358- err = nrfx_gppi_channel_alloc (& data -> ppi_ch [i ][j ]);
359- if (err != NRFX_SUCCESS ) {
358+ int ch ;
359+
360+ rv = nrfx_gppi_domain_conn_alloc (src_d , dst_d , & data -> ppi_h [i ][j ]);
361+ if (rv < 0 ) {
360362 /* Do not free allocated resource. It is a fatal condition,
361363 * system requires reconfiguration.
362364 */
363365 LOG_ERR ("Failed to allocate PPI channel" );
364- return - ENOMEM ;
366+ return rv ;
365367 }
368+ /* Enable connection but at the end disable channel on the source domain. */
369+ nrfx_gppi_conn_enable (data -> ppi_h [i ][j ]);
370+ ch = nrfx_gppi_domain_channel_get (data -> ppi_h [i ][j ], src_d );
371+ __ASSERT_NO_MSG (ch >= 0 );
372+ data -> ppi_ch_mask [i ] |= BIT (ch );
366373 }
374+ nrfx_gppi_channels_disable (src_d , data -> ppi_ch_mask [i ]);
367375
368376 err = nrfx_gpiote_channel_alloc (& config -> gpiote [i ],
369377 & data -> gpiote_ch [i ]);
0 commit comments