Skip to content

Commit 1536a88

Browse files
committed
Comparator: add enabled/disabled typestate
1 parent af8ca56 commit 1536a88

File tree

3 files changed

+194
-117
lines changed

3 files changed

+194
-117
lines changed

examples/comp.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,28 @@ fn main() -> ! {
2020

2121
let gpioa = dp.GPIOA.split(&mut rcc);
2222

23-
let (mut comp1, mut comp2) = dp.COMP.split(&mut rcc);
23+
let (comp1, comp2) = dp.COMP.split(&mut rcc);
2424

2525
let pa1 = gpioa.pa1.into_analog();
2626
let pa0 = gpioa.pa0.into_analog();
27-
comp1.init(pa1, pa0, Config::default());
28-
comp1.enable();
27+
let comp1 = comp1.comparator(pa1, pa0, Config::default(), &rcc.clocks);
28+
let comp1 = comp1.enable();
2929
let mut led1 = gpioa.pa5.into_push_pull_output();
3030

3131
let pa3 = gpioa.pa3.into_analog();
32-
comp2.init(
32+
let comp2 = comp2.comparator(
3333
pa3,
3434
RefintInput::VRefintM12,
3535
Config::default()
3636
.hysteresis(Hysteresis::High)
3737
.output_inverted(),
38+
&rcc.clocks,
3839
);
39-
comp2.enable();
4040
let led2 = gpioa.pa2.into_push_pull_output();
4141
// Configure PA2 to the comparator's alternate function so it gets
4242
// changed directly by the comparator.
4343
comp2.output_pin(led2);
44+
let _comp2 = comp2.enable();
4445

4546
loop {
4647
match comp1.output() {

examples/comp_window.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern crate cortex_m_rt as rt;
88
extern crate panic_halt;
99
extern crate stm32g0xx_hal as hal;
1010

11-
use hal::comparator::{Config, Hysteresis, RefintInput, WindowComparator};
11+
use hal::comparator::{self, Config, Hysteresis, RefintInput};
1212
use hal::prelude::*;
1313
use hal::stm32;
1414
use rt::entry;
@@ -22,15 +22,15 @@ fn main() -> ! {
2222

2323
let pa1 = gpioa.pa1.into_analog();
2424

25-
let (upper, lower) = dp.COMP.split(&mut rcc);
26-
let mut comp = WindowComparator { upper, lower };
27-
comp.init(
25+
let comp = comparator::window_comparator12(
26+
dp.COMP,
2827
pa1,
2928
RefintInput::VRefintM14,
3029
RefintInput::VRefintM34,
3130
Config::default().hysteresis(Hysteresis::Medium),
31+
&mut rcc,
3232
);
33-
comp.enable();
33+
let comp = comp.enable();
3434

3535
let mut led1 = gpioa.pa5.into_push_pull_output();
3636
let mut led2 = gpioa.pa6.into_push_pull_output();

0 commit comments

Comments
 (0)