Skip to content

Commit 153b51a

Browse files
Use descriptive methods on register calls
Note: In fn calibrate, `while self.rb.cr.read().adcal().is_not_complete() {}` would be better than `while !self.rb.cr.read().adcal().is_complete() {}` However this seems to lack in our version of the PAC In fn disable, `self.rb.cr.modify(|_, w| w.aden().disable());` would be better than `self.rb.cr.modify(|_, w| w.aden().clear_bit());` However this seems to lack in our version of the PAC
1 parent a9832b9 commit 153b51a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/adc.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,27 +336,31 @@ macro_rules! adc_hal {
336336

337337
/// sets up adc in one shot mode for a single channel
338338
pub fn setup_oneshot(&mut self) {
339-
// stop and clear overrun events
340-
self.rb.cr.modify(|_, w| w.adstp().set_bit());
341-
self.rb.isr.modify(|_, w| w.ovr().clear_bit());
339+
self.rb.cr.modify(|_, w| w.adstp().stop());
340+
self.rb.isr.modify(|_, w| w.ovr().clear());
342341

343342
self.rb.cfgr.modify(|_, w| w
344-
.cont().clear_bit()
345-
.ovrmod().clear_bit()
343+
.cont().single()
344+
.ovrmod().preserve()
346345
);
347346

348-
self.rb.sqr1.modify(|_, w| w.l().bits(0));
347+
self.set_sequence_len(1);
349348

350349
self.operation_mode = Some(OperationMode::OneShot);
351350
}
352351

352+
fn set_sequence_len(&mut self, len: u8) {
353+
debug_assert!(len <= 16);
354+
self.rb.sqr1.modify(|_, w| w.l().bits(len - 1));
355+
}
356+
353357
fn set_align(&self, align: Align) {
354358
self.rb.cfgr.modify(|_, w| w.align().bit(align.bitvalue()));
355359
}
356360

357361
fn enable(&mut self) {
358-
self.rb.cr.modify(|_, w| w.aden().set_bit());
359-
while self.rb.isr.read().adrdy().bit_is_clear() {}
362+
self.rb.cr.modify(|_, w| w.aden().enable());
363+
while self.rb.isr.read().adrdy().is_not_ready() {}
360364
}
361365

362366
fn disable(&mut self) {
@@ -374,11 +378,10 @@ macro_rules! adc_hal {
374378
self.disable();
375379

376380
self.rb.cr.modify(|_, w| w
377-
// NOTE: needs to be adopted if implementing differential input
378-
.adcaldif().clear_bit()
379-
.adcal() .set_bit());
381+
.adcaldif().single_ended()
382+
.adcal() .calibration());
380383

381-
while self.rb.cr.read().adcal().bit_is_set() {}
384+
while !self.rb.cr.read().adcal().is_complete() {}
382385
}
383386

384387

@@ -407,7 +410,7 @@ macro_rules! adc_hal {
407410
self.set_chan_smps(chan, SampleTime::default());
408411
self.select_single_chan(chan);
409412

410-
self.rb.cr.modify(|_, w| w.adstart().set_bit());
413+
self.rb.cr.modify(|_, w| w.adstart().start());
411414
while self.rb.isr.read().eos().is_not_complete() {}
412415
self.rb.isr.modify(|_, w| w.eos().clear());
413416
return self.rb.dr.read().rdata().bits();

0 commit comments

Comments
 (0)