Why does adc_sample on sam0 disable all (ADC) interrupts?

Dear reading IOTlers,

while trying to use some non-basic ADC features on the SAMD21 I realized that the adc_sample() function of the periph/adc driver of the sam0_common implementation disable all interrupts:

However, I failed to understand why this is done (a comment might help here). Does anyone remember the reason? (The original code is quite old (more than four years).)

Cheers Oleg

Well, if nothing is handling the interrupt, it needs to be disabled. Or what would you expect to happen if the ADC fires an ISR e.g., for the sampling-done event?

@maribu proposed a new ADC API that will also allow for conversions in the background.

Unfortunately it seems like nobody has time to look into that right now.

The current ADC API is indeed quite limited.

1 Like

I think I found the reason in the mean time: interrupts must be disabled when polling for the result.

However, it is suboptimal to have this kind of side effect.

@kaspar, of course, interrupts should be disabled without a ISR defined, but this should be asserted during CPU initialization not in an API function.

Actually this line should not be necessary at all. As long as the ADC interrupt is no enabled in NVIC, setting which bits on the ADC may trigger such an interrupt should not be necessary.