Skip to content

Commit 1ea1347

Browse files
committed
HRTIM - Fix some clippy warnings and fmt - examples
1 parent a79d4b4 commit 1ea1347

File tree

11 files changed

+101
-112
lines changed

11 files changed

+101
-112
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ name = "hrtim-capture"
134134
required-features = ["hrtim"]
135135
path = "examples/hrtim/capture.rs"
136136

137+
[[example]]
138+
name = "hrtim-capture-dma"
139+
required-features = ["hrtim"]
140+
path = "examples/hrtim/capture-dma.rs"
141+
137142
[[example]]
138143
name = "hrtim-eev-comp"
139144
required-features = ["hrtim"]

examples/hrtim/adc-trigger.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
mod utils;
88

99
use cortex_m_rt::entry;
10+
use stm32g4xx_hal::hrtim::HrParts;
1011
use utils::logger::info;
1112

1213
#[entry]
@@ -87,7 +88,14 @@ fn main() -> ! {
8788
let period = 0xFFFF;
8889
let (hr_control, ..) = dp.HRTIM_COMMON.hr_control(&mut rcc).wait_for_calibration();
8990
let mut hr_control = hr_control.constrain();
90-
let (mut timer, (mut cr1, _cr2, mut cr3, mut cr4), (mut out1, mut out2), ..) = dp
91+
let HrParts {
92+
mut timer,
93+
mut cr1,
94+
mut cr3,
95+
mut cr4,
96+
out: (mut out1, mut out2),
97+
..
98+
} = dp
9199
.HRTIM_TIMA
92100
.pwm_advanced((pin_a, pin_b), &mut rcc)
93101
.prescaler(prescaler)

examples/hrtim/capture-dma.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
mod utils;
88

99
use cortex_m_rt::entry;
10+
use stm32g4xx_hal::hrtim::{timer::TimerSplitCapture, HrParts};
1011
use utils::logger::info;
1112

1213
#[entry]
@@ -15,7 +16,7 @@ fn main() -> ! {
1516

1617
use hal::{
1718
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
18-
gpio::{GpioExt, AF13},
19+
gpio::GpioExt,
1920
hrtim::{
2021
capture, compare_register::HrCompareRegister, control::HrControltExt, external_event,
2122
external_event::ToExternalEventSource, output::HrOutput, timer::HrSlaveTimerCpt,
@@ -37,7 +38,7 @@ fn main() -> ! {
3738
let pwr = dp.PWR.constrain().freeze();
3839
let mut rcc = dp.RCC.freeze(
3940
rcc::Config::pll().pll_cfg(rcc::PllConfig {
40-
mux: rcc::PLLSrc::HSI,
41+
mux: rcc::PllSrc::HSI,
4142
n: rcc::PllNMul::MUL_15,
4243
m: rcc::PllMDiv::DIV_1,
4344
r: Some(rcc::PllRDiv::DIV_2),
@@ -83,7 +84,13 @@ fn main() -> ! {
8384
.finalize(&mut hr_control);
8485

8586
let mut hr_control = hr_control.constrain();
86-
let (timer, (mut cr1, _cr2, _cr3, _cr4), mut out1, dma_ch) = dp
87+
let HrParts {
88+
timer,
89+
mut cr1,
90+
out: mut out1,
91+
dma_channel,
92+
..
93+
} = dp
8794
.HRTIM_TIMA
8895
.pwm_advanced(pin_a, &mut rcc)
8996
.prescaler(prescaler)
@@ -93,7 +100,11 @@ fn main() -> ! {
93100
out1.enable_set_event(&timer); // Set high at new period
94101
cr1.set_duty(period / 2);
95102

96-
let (mut timer, mut capture, _capture_ch2) = timer.split_capture();
103+
let TimerSplitCapture {
104+
mut timer,
105+
ch1: mut capture,
106+
..
107+
} = timer.split_capture();
97108
timer.start(&mut hr_control.control);
98109
out1.enable();
99110

@@ -109,7 +120,7 @@ fn main() -> ! {
109120

110121
let first_buffer = cortex_m::singleton!(: [u32; 16] = [0; 16]).unwrap();
111122
let mut transfer = streams.0.into_circ_peripheral_to_memory_transfer(
112-
capture.enable_dma(dma_ch),
123+
capture.enable_dma(dma_channel),
113124
&mut first_buffer[..],
114125
config,
115126
);
@@ -121,7 +132,7 @@ fn main() -> ! {
121132
for duty in (u32::from(period) / 10)..(9 * u32::from(period) / 10) {
122133
let mut data = [0; 2];
123134
transfer.read_exact(&mut data);
124-
let [t1, t2] = data.map(capture::dma_value_to_signed);
135+
let [t1, t2] = data.map(|x| capture::dma_value_to_signed(x, period));
125136
cr1.set_duty(duty as u16);
126137
info!("Capture: t1: {}, t2: {}, duty: {}, ", t1, t2, old_duty);
127138
old_duty = duty;

examples/hrtim/capture.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
mod utils;
88

99
use cortex_m_rt::entry;
10+
use stm32g4xx_hal::hrtim::HrParts;
1011
use utils::logger::info;
1112

1213
#[entry]
@@ -79,19 +80,24 @@ fn main() -> ! {
7980
.finalize(&mut hr_control);
8081

8182
let mut hr_control = hr_control.constrain();
82-
let (mut timer, (mut cr1, _cr2, _cr3, _cr4), mut out1, ..) = dp
83+
let HrParts {
84+
mut timer,
85+
mut cr1,
86+
mut out,
87+
..
88+
} = dp
8389
.HRTIM_TIMA
8490
.pwm_advanced(pin_a, &mut rcc)
8591
.prescaler(prescaler)
8692
.period(period)
8793
.finalize(&mut hr_control);
8894

89-
out1.enable_rst_event(&cr1); // Set low on compare match with cr1
90-
out1.enable_set_event(&timer); // Set high at new period
95+
out.enable_rst_event(&cr1); // Set low on compare match with cr1
96+
out.enable_set_event(&timer); // Set high at new period
9197

9298
cr1.set_duty(period / 2);
9399
timer.start(&mut hr_control.control);
94-
out1.enable();
100+
out.enable();
95101

96102
let capture = timer.capture_ch1();
97103
capture.enable_interrupt(true, &mut hr_control);

examples/hrtim/eev-comp.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
mod utils;
99

1010
use cortex_m_rt::entry;
11+
use stm32g4xx_hal::hrtim::HrParts;
1112
use utils::logger::info;
1213

1314
#[entry]
@@ -107,20 +108,25 @@ fn main() -> ! {
107108
// ------------------------- .--------------------------------------
108109
// . . * . . .
109110
// . . * . . .
110-
let (mut timer, (mut cr1, _cr2, _cr3, _cr4), mut out1, ..) = dp
111+
let HrParts {
112+
mut timer,
113+
mut cr1,
114+
mut out,
115+
..
116+
} = dp
111117
.HRTIM_TIMA
112118
.pwm_advanced(pin_a, &mut rcc)
113119
.prescaler(prescaler)
114120
.eev_cfg(EevCfgs::default().eev4(EevCfg::default()))
115121
.period(0xFFFF)
116122
.finalize(&mut hr_control);
117123

118-
out1.enable_rst_event(&cr1); // Set low on compare match with cr1
119-
out1.enable_rst_event(&eev_input4);
120-
out1.enable_set_event(&timer); // Set high at new period
124+
out.enable_rst_event(&cr1); // Set low on compare match with cr1
125+
out.enable_rst_event(&eev_input4);
126+
out.enable_set_event(&timer); // Set high at new period
121127
cr1.set_duty(timer.get_period() / 3);
122128

123-
out1.enable();
129+
out.enable();
124130
timer.start(&mut hr_control.control);
125131

126132
info!("Started");

examples/hrtim/eev.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
mod utils;
99

1010
use cortex_m_rt::entry;
11+
use stm32g4xx_hal::hrtim::HrParts;
1112
use utils::logger::info;
1213

1314
#[entry]
@@ -79,20 +80,25 @@ fn main() -> ! {
7980
// ------------------------- ------------------------------------------
8081
// . . * . . .
8182
// . . * . . .
82-
let (mut timer, (mut cr1, _cr2, _cr3, _cr4), mut out1, ..) = dp
83+
let HrParts {
84+
mut timer,
85+
mut cr1,
86+
mut out,
87+
..
88+
} = dp
8389
.HRTIM_TIMA
8490
.pwm_advanced(pin_a, &mut rcc)
8591
.prescaler(prescaler)
8692
.eev_cfg(EevCfgs::default())
8793
.period(0xFFFF)
8894
.finalize(&mut hr_control);
8995

90-
out1.enable_rst_event(&cr1); // Set low on compare match with cr1
91-
out1.enable_rst_event(&eev_input3);
92-
out1.enable_set_event(&timer); // Set high at new period
96+
out.enable_rst_event(&cr1); // Set low on compare match with cr1
97+
out.enable_rst_event(&eev_input3);
98+
out.enable_set_event(&timer); // Set high at new period
9399
cr1.set_duty(timer.get_period() / 3);
94100

95-
out1.enable();
101+
out.enable();
96102
timer.start(&mut hr_control.control);
97103

98104
info!("Started");

examples/hrtim/flt-comp.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
mod utils;
99

1010
use cortex_m_rt::entry;
11+
use stm32g4xx_hal::hrtim::HrParts;
1112
use utils::logger::info;
1213

1314
#[entry]
@@ -108,7 +109,12 @@ fn main() -> ! {
108109
// ----------------------------------------- --------------------------
109110
// . . . * . .
110111
// . . . * . .
111-
let (mut timer, (mut cr1, _cr2, _cr3, _cr4), mut out1, ..) = dp
112+
let HrParts {
113+
mut timer,
114+
mut cr1,
115+
out: mut out1,
116+
..
117+
} = dp
112118
.HRTIM_TIMA
113119
.pwm_advanced(pin_a, &mut rcc)
114120
.prescaler(prescaler)

examples/hrtim/flt.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
mod utils;
99

1010
use cortex_m_rt::entry;
11+
use stm32g4xx_hal::hrtim::HrParts;
1112
use utils::logger::info;
1213

1314
#[entry]
@@ -74,7 +75,12 @@ fn main() -> ! {
7475
// ----------------------------------------- --------------------------
7576
// . . . * . .
7677
// . . . * . .
77-
let (mut timer, (mut cr1, _cr2, _cr3, _cr4), mut out1, ..) = dp
78+
let HrParts {
79+
mut timer,
80+
mut cr1,
81+
mut out,
82+
..
83+
} = dp
7884
.HRTIM_TIMA
7985
.pwm_advanced(pin_a, &mut rcc)
8086
.prescaler(prescaler)
@@ -92,23 +98,23 @@ fn main() -> ! {
9298
// as normal
9399
.finalize(&mut hr_control);
94100

95-
out1.enable_rst_event(&cr1); // Set low on compare match with cr1
96-
out1.enable_set_event(&timer); // Set high at new period
101+
out.enable_rst_event(&cr1); // Set low on compare match with cr1
102+
out.enable_set_event(&timer); // Set high at new period
97103
cr1.set_duty(timer.get_period() / 3);
98104
//unsafe {((HRTIM_COMMON::ptr() as *mut u8).offset(0x14) as *mut u32).write_volatile(1); }
99-
out1.enable();
105+
out.enable();
100106
timer.start(&mut hr_control.control);
101107

102108
info!("Started");
103109

104110
loop {
105111
for _ in 0..5 {
106112
delay.delay(500_u32.millis());
107-
info!("State: {:?}", out1.get_state());
113+
info!("State: {:?}", out.get_state());
108114
}
109115
if hr_control.fault_3.is_fault_active() {
110116
hr_control.fault_3.clear_fault(); // Clear fault every 5s
111-
out1.enable();
117+
out.enable();
112118
info!("failt cleared, and output reenabled");
113119
}
114120
}

examples/hrtim/hrtim.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
mod utils;
88

99
use cortex_m_rt::entry;
10+
use stm32g4xx_hal::hrtim::HrParts;
1011
use utils::logger::info;
1112

1213
#[entry]
@@ -69,7 +70,12 @@ fn main() -> ! {
6970
let (hr_control, ..) = dp.HRTIM_COMMON.hr_control(&mut rcc).wait_for_calibration();
7071
let mut hr_control = hr_control.constrain();
7172

72-
let (mut timer, (mut cr1, _cr2, _cr3, _cr4), (mut out1, mut out2), ..) = dp
73+
let HrParts {
74+
mut timer,
75+
mut cr1,
76+
out: (mut out1, mut out2),
77+
..
78+
} = dp
7379
.HRTIM_TIMA
7480
.pwm_advanced((pin_a, pin_b), &mut rcc)
7581
.prescaler(prescaler)

examples/hrtim/master.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
mod utils;
88

99
use cortex_m_rt::entry;
10+
use stm32g4xx_hal::hrtim::HrParts;
1011
use utils::logger::info;
1112

1213
#[entry]
@@ -68,7 +69,12 @@ fn main() -> ! {
6869
let (hr_control, ..) = dp.HRTIM_COMMON.hr_control(&mut rcc).wait_for_calibration();
6970
let mut hr_control = hr_control.constrain();
7071

71-
let (mut timer, (mut cr1, _cr2, _cr3, _cr4), (mut out1, mut out2), ..) = dp
72+
let HrParts {
73+
mut timer,
74+
mut cr1,
75+
out: (mut out1, mut out2),
76+
..
77+
} = dp
7278
.HRTIM_TIMA
7379
.pwm_advanced((pin_a, pin_b), &mut rcc)
7480
.prescaler(prescaler)
@@ -80,7 +86,11 @@ fn main() -> ! {
8086
.timer_mode(HrTimerMode::SingleShotRetriggerable)
8187
.finalize(&mut hr_control);
8288

83-
let (mut mtimer, (mut mcr1, _mcr2, _mcr3, _mcr4), ..) = dp
89+
let HrParts {
90+
timer: mut mtimer,
91+
cr1: mut mcr1,
92+
..
93+
} = dp
8494
.HRTIM_MASTER
8595
.pwm_advanced((), &mut rcc)
8696
.prescaler(prescaler)

0 commit comments

Comments
 (0)