drivers: pwm_nrf5_sw: Correctly use allocated GPIOTE channels

The driver improperly uses the PWM channel index to reference
the GPIOTE channel to be used for the PWM signal generation.
Consequently, the PWM signal on a given channel can be correctly
generated only if both those indexes are by chance the same.
Fix this by switching to use the stored index of the actually
allocated GPIOTE channel.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
Andrzej Głąbek 2022-04-08 16:44:21 +02:00 committed by Carles Cufí
commit f73618906d

View file

@ -237,11 +237,11 @@ static int pwm_nrf5_sw_pin_set(const struct device *dev, uint32_t pwm,
NRF_PPI->CH[ppi_chs[0]].EEP = NRF_PPI->CH[ppi_chs[0]].EEP =
(uint32_t) &(rtc->EVENTS_COMPARE[channel]); (uint32_t) &(rtc->EVENTS_COMPARE[channel]);
NRF_PPI->CH[ppi_chs[0]].TEP = NRF_PPI->CH[ppi_chs[0]].TEP =
(uint32_t) &(NRF_GPIOTE->TASKS_OUT[channel]); (uint32_t) &(NRF_GPIOTE->TASKS_OUT[gpiote_ch]);
NRF_PPI->CH[ppi_chs[1]].EEP = NRF_PPI->CH[ppi_chs[1]].EEP =
(uint32_t) &(rtc->EVENTS_COMPARE[config->map_size]); (uint32_t) &(rtc->EVENTS_COMPARE[config->map_size]);
NRF_PPI->CH[ppi_chs[1]].TEP = NRF_PPI->CH[ppi_chs[1]].TEP =
(uint32_t) &(NRF_GPIOTE->TASKS_OUT[channel]); (uint32_t) &(NRF_GPIOTE->TASKS_OUT[gpiote_ch]);
NRF_PPI->CH[ppi_chs[2]].EEP = NRF_PPI->CH[ppi_chs[2]].EEP =
(uint32_t) &(rtc->EVENTS_COMPARE[config->map_size]); (uint32_t) &(rtc->EVENTS_COMPARE[config->map_size]);
NRF_PPI->CH[ppi_chs[2]].TEP = NRF_PPI->CH[ppi_chs[2]].TEP =
@ -250,11 +250,11 @@ static int pwm_nrf5_sw_pin_set(const struct device *dev, uint32_t pwm,
NRF_PPI->CH[ppi_chs[0]].EEP = NRF_PPI->CH[ppi_chs[0]].EEP =
(uint32_t) &(timer->EVENTS_COMPARE[channel]); (uint32_t) &(timer->EVENTS_COMPARE[channel]);
NRF_PPI->CH[ppi_chs[0]].TEP = NRF_PPI->CH[ppi_chs[0]].TEP =
(uint32_t) &(NRF_GPIOTE->TASKS_OUT[channel]); (uint32_t) &(NRF_GPIOTE->TASKS_OUT[gpiote_ch]);
NRF_PPI->CH[ppi_chs[1]].EEP = NRF_PPI->CH[ppi_chs[1]].EEP =
(uint32_t) &(timer->EVENTS_COMPARE[config->map_size]); (uint32_t) &(timer->EVENTS_COMPARE[config->map_size]);
NRF_PPI->CH[ppi_chs[1]].TEP = NRF_PPI->CH[ppi_chs[1]].TEP =
(uint32_t) &(NRF_GPIOTE->TASKS_OUT[channel]); (uint32_t) &(NRF_GPIOTE->TASKS_OUT[gpiote_ch]);
} }
NRF_PPI->CHENSET = ppi_mask; NRF_PPI->CHENSET = ppi_mask;