Skip to content

Commit 9ea3dcf

Browse files
refactoring based on review
1 parent 09af232 commit 9ea3dcf

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/adc.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -412,22 +412,15 @@ macro_rules! adc_hal {
412412
self.select_single_chan(chan);
413413

414414
self.rb.cr.modify(|_, w| w.adstart().set_bit());
415-
while self.rb.isr.read().eos().is_not_complete()
416-
{}
415+
while self.rb.isr.read().eos().is_not_complete() {}
417416
self.rb.isr.modify(|_, w| w.eos().clear());
418417
return self.rb.dr.read().rdata().bits();
419418
}
420419

421420
fn ensure_oneshot(&mut self) {
422-
match self.operation_mode {
423-
Some(mode) =>
424-
{
425-
if mode != OperationMode::OneShot {
426-
self.setup_oneshot();
427-
}
428-
},
429-
_ => self.setup_oneshot(),
430-
};
421+
if self.operation_mode != Some(OperationMode::OneShot) {
422+
self.setup_oneshot();
423+
}
431424
}
432425

433426
/// This should only be invoked with the defined channels for the particular
@@ -490,10 +483,12 @@ macro_rules! adc12_hal {
490483
)+) => {
491484
$(
492485
impl Adc<$ADC> {
486+
/// Returns true iff
487+
/// the clock can be enabled with the given settings
488+
/// or the clock was already enabled with the same settings
493489
fn enable_clock(&self, ahb: &mut AHB, adc_common: &mut ADC1_2) -> bool {
494-
if ahb.enr().read().adc34en().is_enabled() &&
495-
(adc_common.ccr.read().ckmode().variant() != self.ckmode.into()) {
496-
return false;
490+
if ahb.enr().read().adc12en().is_enabled() {
491+
return (adc_common.ccr.read().ckmode().variant() == self.ckmode.into());
497492
}
498493
ahb.enr().modify(|_, w| w.adc12en().enabled());
499494
adc_common.ccr.modify(|_, w| w
@@ -525,11 +520,11 @@ macro_rules! adc34_hal {
525520
$(
526521
impl Adc<$ADC> {
527522
/// Returns true iff
528-
/// the clock was enabled
523+
/// the clock can be enabled with the given settings
529524
/// or the clock was already enabled with the same settings
530525
fn enable_clock(&self, ahb: &mut AHB, adc_common: &mut ADC3_4) -> bool {
531526
if ahb.enr().read().adc34en().is_enabled() {
532-
return (adc_common.ccr.read().ckmode().variant() == self.ckmode.into())
527+
return (adc_common.ccr.read().ckmode().variant() == self.ckmode.into());
533528
}
534529
ahb.enr().modify(|_, w| w.adc34en().enabled());
535530
adc_common.ccr.modify(|_, w| w

0 commit comments

Comments
 (0)