Skip to content

Commit f2e0a44

Browse files
authored
Fix Enable multiple (#13)
* Fix Start/stop multiple timers and start timers in examples * Fix examples not compiling * fmt
1 parent 6af73f2 commit f2e0a44

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

examples/stm32g4/.cargo/config.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[target.thumbv7em-none-eabihf]
22
runner = 'probe-rs run --connect-under-reset'
33
rustflags = [
4-
"-C", "link-arg=-Tlink.x",
54
"-C", "link-arg=-Tdefmt.x",
65
]
76

examples/stm32g4/src/bin/hrtim.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ fn main() -> ! {
9090
out1.enable();
9191
out2.enable();
9292

93+
timer.start(&mut hr_control.control);
94+
9395
loop {
9496
// Step frequency from 14.6kHz to about 146kHz(half of that when only looking at one pin)
9597
for i in 1..=10 {

examples/stm32g4/src/bin/master.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ fn main() -> ! {
106106
out1.enable();
107107
out2.enable();
108108

109+
hr_control
110+
.control
111+
.start_stop_timers(|w| w.start(&mut mtimer).start(&mut timer));
112+
109113
defmt::info!("Running");
110114

111115
loop {

src/control.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::fault::{
66
FltMonitor1, FltMonitor2, FltMonitor3, FltMonitor4, FltMonitor5, FltMonitorSys,
77
};
88

9-
use crate::timer;
9+
use crate::timer::{self, HrTimer};
1010
use crate::{pac, pac::HRTIM_COMMON};
1111

1212
use super::{external_event::EevInputs, fault::FaultInputs};
@@ -272,16 +272,20 @@ pub struct HrPwmCtrl;
272272
pub struct Foo<'a>(&'a mut pac::hrtim_master::cr::W);
273273

274274
impl<'a> Foo<'a> {
275-
pub fn start<TIM: timer::Instance>(self, _t: &mut TIM) -> Self {
275+
pub fn start<T: HrTimer>(self, _t: &mut T) -> Self {
276+
use crate::timer::Instance;
277+
276278
let w = self.0;
277-
Foo(match TIM::TIMX {
279+
Foo(match T::Timer::TIMX {
278280
timer::Timer::Master => w.mcen().set_bit(),
279281
timer::Timer::Tim(v) => w.tcen(v as _).set_bit(),
280282
})
281283
}
282-
pub fn stop<TIM: timer::Instance>(self, _t: &mut TIM) -> Self {
284+
pub fn stop<T: HrTimer>(self, _t: &mut T) -> Self {
285+
use crate::timer::Instance;
286+
283287
let w = self.0;
284-
Foo(match TIM::TIMX {
288+
Foo(match T::Timer::TIMX {
285289
timer::Timer::Master => w.mcen().clear_bit(),
286290
timer::Timer::Tim(v) => w.tcen(v as _).clear_bit(),
287291
})

src/timer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub struct DmaChannel<TIM> {
115115
}
116116

117117
pub trait HrTimer {
118-
type Timer;
118+
type Timer: Instance;
119119
type Prescaler: HrtimPrescaler;
120120
type DacResetTrigger: DacResetTrigger;
121121

0 commit comments

Comments
 (0)