Skip to content

Commit 83e5b28

Browse files
committed
fix
1 parent cc99237 commit 83e5b28

File tree

6 files changed

+43
-51
lines changed

6 files changed

+43
-51
lines changed

examples/adc-continious.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ fn main() -> ! {
4242

4343
info!("Setup Gpio");
4444
let gpioa = dp.GPIOA.split(&mut rcc);
45-
let pa0 = gpioa.pa0.into_analog();
4645

4746
info!("Setup Adc1");
4847
let mut delay = cp.SYST.delay(&rcc.clocks);
@@ -54,7 +53,7 @@ fn main() -> ! {
5453
adc.set_auto_delay(true);
5554
adc.set_continuous(Continuous::Continuous);
5655
adc.reset_sequence();
57-
adc.configure_channel(&pa0, Sequence::One, SampleTime::Cycles_640_5);
56+
adc.configure_channel(&gpioa.pa0, Sequence::One, SampleTime::Cycles_640_5);
5857
adc.configure_channel(&Vref, Sequence::Two, SampleTime::Cycles_640_5);
5958
adc.configure_channel(&Temperature, Sequence::Three, SampleTime::Cycles_640_5);
6059
let adc = adc.enable();

examples/adc-one-shot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ fn main() -> ! {
4343
info!("Setup Gpio");
4444

4545
let gpioa = dp.GPIOA.split(&mut rcc);
46-
let pa7 = gpioa.pa7.into_analog();
4746

4847
info!("Enter Loop");
4948

5049
loop {
5150
info!("Convert");
52-
let sample = adc.convert(&pa7, SampleTime::Cycles_640_5);
51+
let sample = adc.convert(&gpioa.pa7, SampleTime::Cycles_640_5);
5352
info!("sample to mv");
5453
let millivolts = adc.sample_to_millivolts(sample);
5554
info!("pa7: {}mV", millivolts);

examples/button.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use cortex_m_rt::entry;
1717

1818
type ButtonPin = gpio::PC13<Input>;
1919

20-
// Make LED pin globally available
20+
// Make LED and BUTTON pins globally available
2121
static G_BUTTON: Mutex<RefCell<Option<ButtonPin>>> = Mutex::new(RefCell::new(None));
2222
static G_LED_ON: AtomicBool = AtomicBool::new(true);
2323

examples/comp.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,33 @@
99
#![no_std]
1010

1111
mod utils;
12-
extern crate cortex_m_rt as rt;
1312

14-
use rt::entry;
13+
use cortex_m_rt::entry;
1514

1615
#[entry]
1716
fn main() -> ! {
18-
use hal::comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis};
19-
use hal::gpio::{GpioExt, PushPull};
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");
2525
let mut rcc = dp.RCC.constrain();
2626

2727
let gpioa = dp.GPIOA.split(&mut rcc);
2828

2929
let (comp1, comp2, ..) = dp.COMP.split(&mut rcc);
3030

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);
3432
let comp1 = comp1.enable();
3533

3634
// led1 pa1 will be updated manually when to match comp1 value
3735
let mut led1 = gpioa.pa5.into_push_pull_output();
3836

39-
let pa7 = gpioa.pa7.into_analog();
4037
let comp2 = comp2.comparator(
41-
pa7,
38+
gpioa.pa7,
4239
refint_input::VRefintM12,
4340
Config::default()
4441
.hysteresis(Hysteresis::None)
@@ -53,9 +50,6 @@ fn main() -> ! {
5350

5451
loop {
5552
// 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());
6054
}
6155
}

examples/comp_w_dac.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ use rt::entry;
1010

1111
#[entry]
1212
fn main() -> ! {
13-
use hal::comparator::{self, ComparatorExt, ComparatorSplit};
14-
use hal::dac::{Dac1IntSig1, DacExt, DacOut};
15-
use hal::delay::SYSTDelayExt;
16-
use hal::gpio::{GpioExt, PushPull};
17-
use hal::rcc::RccExt;
18-
use hal::stasis::Freeze;
19-
use hal::stm32;
20-
use stm32g4xx_hal as hal;
13+
use stm32g4xx_hal::{
14+
comparator::{self, ComparatorExt, ComparatorSplit},
15+
dac::{Dac1IntSig1, DacExt, DacOut},
16+
delay::SYSTDelayExt,
17+
gpio::{GpioExt, PushPull},
18+
pac,
19+
rcc::RccExt,
20+
stasis::Freeze,
21+
};
2122

22-
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
23+
let dp = pac::Peripherals::take().expect("cannot take peripherals");
2324
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
2425

2526
let mut rcc = dp.RCC.constrain();
@@ -34,13 +35,14 @@ fn main() -> ! {
3435
let (mut dac, [dac_token]) = dac.freeze();
3536

3637
let (comp1, _comp2, ..) = dp.COMP.split(&mut rcc);
37-
let pa1 = gpioa.pa1.into_analog();
3838

3939
// Set up comparator with pa1 as positive, and the DAC as negative input
4040
let comp = comp1.comparator(
41-
pa1,
41+
gpioa.pa1,
4242
dac_token,
43-
comparator::Config::default().hysteresis(comparator::Hysteresis::None),
43+
comparator::Config::default()
44+
.hysteresis(comparator::Hysteresis::None)
45+
.output_inverted(),
4446
&rcc.clocks,
4547
);
4648

examples/cordic.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@
33
#![no_main]
44
#![no_std]
55

6-
extern crate cortex_m;
7-
extern crate cortex_m_rt as rt;
8-
extern crate stm32g4xx_hal as hal;
9-
10-
use hal::cordic::{
11-
op::{dynamic::Mode as _, Magnitude, SinCos, Sqrt},
12-
prec::P60,
13-
scale::N0,
14-
types::{I1F15, Q15, Q31},
15-
Ext as _,
6+
use cortex_m_rt::entry;
7+
use stm32g4xx_hal::{
8+
cordic::{
9+
op::{dynamic::Mode as _, Magnitude, SinCos, Sqrt},
10+
prec::P60,
11+
scale::N0,
12+
types::{I1F15, Q15, Q31},
13+
Ext as _,
14+
},
15+
pac,
16+
prelude::*,
17+
pwr::PwrExt,
18+
rcc::Config,
1619
};
17-
use hal::prelude::*;
18-
use hal::pwr::PwrExt;
19-
use hal::rcc::Config;
20-
use hal::stm32;
21-
use rt::entry;
2220

2321
#[macro_use]
2422
mod utils;
@@ -27,7 +25,7 @@ use utils::logger::println;
2725

2826
#[entry]
2927
fn main() -> ! {
30-
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
28+
let dp = pac::Peripherals::take().expect("cannot take peripherals");
3129
let pwr = dp.PWR.constrain().freeze();
3230
let mut rcc = dp.RCC.freeze(Config::hsi(), pwr);
3331

0 commit comments

Comments
 (0)