Skip to content

Commit ee7c010

Browse files
boondocklabsusbalbin
authored andcommitted
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.
1 parent ffaf5c5 commit ee7c010

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/adc/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,14 +714,14 @@ impl<ADC: Instance> DynamicAdc<ADC> {
714714
#[inline(always)]
715715
pub fn set_end_of_conversion_interrupt(&mut self, eoc: config::Eoc) {
716716
self.config.end_of_conversion_interrupt = eoc;
717-
let (en, eocs) = match eoc {
717+
let (en_eoc, en_eos) = match eoc {
718718
config::Eoc::Disabled => (false, false),
719-
config::Eoc::Conversion => (true, true),
720-
config::Eoc::Sequence => (true, false),
719+
config::Eoc::Conversion => (true, false),
720+
config::Eoc::Sequence => (false, true),
721721
};
722722
self.adc_reg
723723
.ier()
724-
.modify(|_, w| w.eosie().bit(eocs).eocie().bit(en));
724+
.modify(|_, w| w.eosie().bit(en_eos).eocie().bit(en_eoc));
725725
}
726726

727727
/// Enable/disable overrun interrupt
@@ -902,6 +902,12 @@ impl<ADC: Instance> DynamicAdc<ADC> {
902902
self.adc_reg.isr().modify(|_, w| w.eoc().clear());
903903
}
904904

905+
/// Resets the end-of-sequence flag
906+
#[inline(always)]
907+
pub fn clear_end_of_sequence_flag(&mut self) {
908+
self.adc_reg.isr().modify(|_, w| w.eos().clear());
909+
}
910+
905911
/// Block until the conversion is completed and return to configured
906912
pub fn wait_for_conversion_sequence(&mut self) {
907913
while !self.adc_reg.isr().read().eoc().bit_is_set() {}
@@ -1445,6 +1451,12 @@ impl<ADC: Instance> Adc<ADC, Active> {
14451451
pub fn clear_end_conversion_flag(&mut self) {
14461452
self.adc.clear_end_of_conversion_flag();
14471453
}
1454+
1455+
/// Clear the end of sequence interrupt flag
1456+
#[inline(always)]
1457+
pub fn clear_end_sequence_flag(&mut self) {
1458+
self.adc.clear_end_of_sequence_flag();
1459+
}
14481460
}
14491461

14501462
impl<ADC: Instance> Adc<ADC, DMA> {

0 commit comments

Comments
 (0)