From f74bdd9b2393a4042aed8793ddffcda742ff4df1 Mon Sep 17 00:00:00 2001 From: boondockenergy Date: Mon, 21 Jul 2025 14:32:23 -0700 Subject: [PATCH] Fix ADC eoc/eos interrupts When enabling ADC interrupts using `Eoc::Conversion`, both end of sequence and end of conversion interrupts were being enabled, with no way to clear the end of sequence interrupt. When selecting `Eoc::Sequence`, just the end of conversion interrupt was being enabled. This fixes the enabled interrupt flags in EOSIE, and adds a `clear_end_sequence_flag` method to clear the end of sequence flag. --- src/adc/mod.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/adc/mod.rs b/src/adc/mod.rs index 9ed3a903..12d75282 100644 --- a/src/adc/mod.rs +++ b/src/adc/mod.rs @@ -714,14 +714,14 @@ impl DynamicAdc { #[inline(always)] pub fn set_end_of_conversion_interrupt(&mut self, eoc: config::Eoc) { self.config.end_of_conversion_interrupt = eoc; - let (en, eocs) = match eoc { + let (en_eoc, en_eos) = match eoc { config::Eoc::Disabled => (false, false), - config::Eoc::Conversion => (true, true), - config::Eoc::Sequence => (true, false), + config::Eoc::Conversion => (true, false), + config::Eoc::Sequence => (false, true), }; self.adc_reg .ier() - .modify(|_, w| w.eosie().bit(eocs).eocie().bit(en)); + .modify(|_, w| w.eosie().bit(en_eos).eocie().bit(en_eoc)); } /// Enable/disable overrun interrupt @@ -902,6 +902,12 @@ impl DynamicAdc { self.adc_reg.isr().modify(|_, w| w.eoc().clear()); } + /// Resets the end-of-sequence flag + #[inline(always)] + pub fn clear_end_of_sequence_flag(&mut self) { + self.adc_reg.isr().modify(|_, w| w.eos().clear()); + } + /// Block until the conversion is completed and return to configured pub fn wait_for_conversion_sequence(&mut self) { while !self.adc_reg.isr().read().eoc().bit_is_set() {} @@ -1445,6 +1451,12 @@ impl Adc { pub fn clear_end_conversion_flag(&mut self) { self.adc.clear_end_of_conversion_flag(); } + + /// Clear the end of sequence interrupt flag + #[inline(always)] + pub fn clear_end_sequence_flag(&mut self) { + self.adc.clear_end_of_sequence_flag(); + } } impl Adc {