Skip to content

Commit b47449d

Browse files
committed
alt-pwm
1 parent a36bb93 commit b47449d

File tree

13 files changed

+370
-519
lines changed

13 files changed

+370
-519
lines changed

examples/pwm-dead-time.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ use panic_halt as _; // panic handler
99
use cortex_m_rt::entry;
1010
use stm32f4xx_hal as hal;
1111

12-
use crate::hal::{pac, prelude::*, timer::Channel, timer::Polarity};
12+
use hal::{
13+
pac,
14+
prelude::*,
15+
timer::Channel,
16+
timer::{Channel1, Polarity},
17+
};
1318

1419
#[entry]
1520
fn main() -> ! {
@@ -20,7 +25,7 @@ fn main() -> ! {
2025

2126
let gpioa = dp.GPIOA.split();
2227

23-
let channels = (gpioa.pa8.into_alternate(), gpioa.pa7.into_alternate());
28+
let channels = Channel1::new(gpioa.pa8).with_complementary(gpioa.pa7);
2429

2530
let mut pwm = dp.TIM1.pwm_hz(channels, 20.kHz(), &clocks);
2631

examples/pwm-input.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
use panic_halt as _;
77

88
use cortex_m_rt::entry;
9-
use stm32f4xx_hal::{pac, prelude::*, timer::Timer};
9+
use stm32f4xx_hal::{
10+
pac,
11+
prelude::*,
12+
timer::{Channel1, Channel2, Timer},
13+
};
1014

1115
#[entry]
1216
fn main() -> ! {
@@ -18,7 +22,7 @@ fn main() -> ! {
1822
let gpioa = dp.GPIOA.split();
1923
let gpioc = dp.GPIOC.split();
2024

21-
let channels = (gpioa.pa8.into_alternate(), gpioa.pa9.into_alternate());
25+
let channels = (Channel1::new(gpioa.pa8), Channel2::new(gpioa.pa9));
2226
// configure tim1 as a PWM output of known frequency.
2327
let pwm = Timer::new(dp.TIM1, &clocks).pwm_hz(channels, 501.Hz());
2428
let (mut ch1, _ch2) = pwm.split();

examples/pwm-sinus.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ use panic_halt as _;
88
use core::f32::consts::FRAC_PI_2;
99
use cortex_m_rt::entry;
1010
use micromath::F32Ext;
11-
use stm32f4xx_hal::{pac, prelude::*, timer::Channel};
11+
use stm32f4xx_hal::{
12+
pac,
13+
prelude::*,
14+
timer::{Channel, Channel1, Channel2},
15+
};
1216

1317
#[entry]
1418
fn main() -> ! {
@@ -18,7 +22,7 @@ fn main() -> ! {
1822
let clocks = rcc.cfgr.use_hse(25.MHz()).freeze();
1923

2024
let gpioa = dp.GPIOA.split();
21-
let channels = (gpioa.pa8.into_alternate(), gpioa.pa9.into_alternate());
25+
let channels = (Channel1::new(gpioa.pa8), Channel2::new(gpioa.pa9));
2226

2327
let mut pwm = dp.TIM1.pwm_us(channels, 100.micros(), &clocks);
2428
let mut counter = dp.TIM2.counter_us(&clocks);

examples/pwm.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
use panic_halt as _;
77

88
use cortex_m_rt::entry;
9-
use stm32f4xx_hal::{pac, prelude::*};
9+
use stm32f4xx_hal::{
10+
pac,
11+
prelude::*,
12+
timer::{Channel1, Channel2},
13+
};
1014

1115
#[entry]
1216
fn main() -> ! {
@@ -16,7 +20,7 @@ fn main() -> ! {
1620
let clocks = rcc.cfgr.freeze();
1721

1822
let gpioa = dp.GPIOA.split();
19-
let channels = (gpioa.pa8.into_alternate(), gpioa.pa9.into_alternate());
23+
let channels = (Channel1::new(gpioa.pa8), Channel2::new(gpioa.pa9));
2024

2125
let pwm = dp.TIM1.pwm_hz(channels, 20.kHz(), &clocks).split();
2226
let (mut ch1, _ch2) = pwm;

examples/rtic-tick.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ mod app {
3636
(Shared {}, Local { led }, init::Monotonics(mono))
3737
}
3838

39-
#[idle]
40-
fn idle(_: idle::Context) -> ! {
41-
loop {}
42-
}
43-
4439
#[task(local = [led])]
4540
fn tick(ctx: tick::Context) {
4641
tick::spawn_after(1.secs()).ok();

0 commit comments

Comments
 (0)