|
9 | 9 | #![no_std] |
10 | 10 |
|
11 | 11 | mod utils; |
12 | | -extern crate cortex_m_rt as rt; |
13 | 12 |
|
14 | | -use rt::entry; |
| 13 | +use cortex_m_rt::entry; |
15 | 14 |
|
16 | 15 | #[entry] |
17 | 16 | fn main() -> ! { |
18 | | - use hal::comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis}; |
19 | | - use hal::gpio::GpioExt; |
20 | | - use hal::rcc::RccExt; |
21 | | - use hal::stm32; |
22 | | - use stm32g4xx_hal as hal; |
23 | | - |
24 | | - let dp = stm32::Peripherals::take().expect("cannot take peripherals"); |
| 17 | + use stm32g4xx_hal::{ |
| 18 | + comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis}, |
| 19 | + gpio::{GpioExt, PushPull}, |
| 20 | + pac, |
| 21 | + rcc::RccExt, |
| 22 | + }; |
| 23 | + |
| 24 | + let dp = pac::Peripherals::take().expect("cannot take peripherals"); |
25 | 25 | let mut rcc = dp.RCC.constrain(); |
26 | 26 |
|
27 | 27 | let gpioa = dp.GPIOA.split(&mut rcc); |
28 | 28 |
|
29 | 29 | let (comp1, comp2, ..) = dp.COMP.split(&mut rcc); |
30 | 30 |
|
31 | | - let pa1 = gpioa.pa1.into_analog(); |
32 | | - let pa0 = gpioa.pa0.into_analog(); |
33 | | - let comp1 = comp1.comparator(pa1, pa0, Config::default(), &rcc.clocks); |
| 31 | + let comp1 = comp1.comparator(gpioa.pa1, gpioa.pa0, Config::default(), &rcc.clocks); |
34 | 32 | let comp1 = comp1.enable(); |
35 | 33 |
|
36 | 34 | // led1 pa1 will be updated manually when to match comp1 value |
37 | 35 | let mut led1 = gpioa.pa5.into_push_pull_output(); |
38 | 36 |
|
39 | | - let pa7 = gpioa.pa7.into_analog(); |
40 | 37 | let comp2 = comp2.comparator( |
41 | | - pa7, |
| 38 | + gpioa.pa7, |
42 | 39 | refint_input::VRefintM12, |
43 | 40 | Config::default() |
44 | 41 | .hysteresis(Hysteresis::None) |
45 | 42 | .output_inverted(), |
46 | 43 | &rcc.clocks, |
47 | 44 | ); |
48 | | - let led2 = gpioa.pa12.into_push_pull_output(); |
| 45 | + let led2 = gpioa.pa12; |
49 | 46 | // Configure PA12 to the comparator's alternate function so it gets |
50 | 47 | // changed directly by the comparator. |
51 | | - comp2.output_pin(led2); |
| 48 | + comp2.output_pin::<PushPull>(led2); |
52 | 49 | let _comp2 = comp2.enable().lock(); |
53 | 50 |
|
54 | 51 | loop { |
55 | 52 | // Read comp1 output and update led1 accordingly |
56 | | - match comp1.output() { |
57 | | - true => led1.set_high(), |
58 | | - false => led1.set_low(), |
59 | | - } |
| 53 | + led1.set_state(comp1.output().into()); |
60 | 54 | } |
61 | 55 | } |
0 commit comments