Skip to content

Commit 16567c7

Browse files
bors[bot]burrbull
andauthored
Merge #497
497: SysMonoTimerExt r=therealprof a=burrbull r? `@therealprof` should I enable `rtic` feature by-default / remove it ? Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents 74213da + 6ac43f0 commit 16567c7

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

CHANGELOG.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,33 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- update `stm32f4` to 0.15.1 [#481]
13+
- use `stm32_i2s_v12x` version 0.3, reexport it, and implements requirement for it [#490]
14+
- i2s module don't reuse marker from spi module and define its own [#490]
15+
- `i2s-audio-out` example updated and now use pcm5102 dac module instead one from discovery board [#490]
16+
- extend visibility of gpio/marker to crate since i2s module require it [#490]
17+
- Bump `synopsys-usb-otg` to `0.3.0` [#508]
18+
- Bump `embedded-hal` to `1.0.0-alpha.8` [#510]
19+
20+
### Removed
21+
- `i2s-audio-out-dma.rs` example, too difficult to fix.
22+
1023
### Added
1124

1225
- Implementation of From trait for Pin-to-PartiallyErasedPin [#507]
1326
- Implementation of From trait for Pin-to-ErasedPin [#507]
1427
- Implementation of From trait for PartiallyErasedPin-to-ErasedPin [#507]
28+
- `SysMonoTimerExt` helper trait, `Pwm::(get/set)_duty_time` [#497]
29+
- example of using i2s in out with rtic and interrupt.
1530

31+
[#489]: https://github.com/stm32-rs/stm32f4xx-hal/pull/489
32+
[#490]: https://github.com/stm32-rs/stm32f4xx-hal/pull/490
33+
[#497]: https://github.com/stm32-rs/stm32f4xx-hal/pull/497
1634
[#507]: https://github.com/stm32-rs/stm32f4xx-hal/pull/507
17-
18-
### Changed
19-
20-
- update `stm32f4` to 0.15.1
21-
- use `stm32_i2s_v12x` version 0.3, reexport it, and implements requirement for it
22-
- i2s module don't reuse marker from spi module and define its own.
23-
- `i2s-audio-out` example updated and now use pcm5102 dac module instead one from discovery board.
24-
- extend visibility of gpio/marker to crate since i2s module require it.
25-
- Bump `synopsys-usb-otg` to `0.3.0`
26-
- Bump `embedded-hal` to `1.0.0-alpha.8`
27-
28-
### Added
29-
- example of using i2s in out with rtic and interrupt.
30-
31-
### Removed
32-
- `i2s-audio-out-dma.rs` example, too difficult to fix.
35+
[#508]: https://github.com/stm32-rs/stm32f4xx-hal/pull/508
36+
[#510]: https://github.com/stm32-rs/stm32f4xx-hal/pull/510
3337

3438
## [v0.13.2] - 2022-05-16
3539

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repository = "https://github.com/stm32-rs/stm32f4xx-hal"
2323
version = "0.13.2"
2424

2525
[package.metadata.docs.rs]
26-
features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd"]
26+
features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd", "rtic"]
2727
targets = ["thumbv7em-none-eabihf"]
2828

2929
[dependencies]
@@ -44,6 +44,7 @@ display-interface = { version = "0.4.1", optional = true }
4444
fugit = "0.3.5"
4545
fugit-timer = "0.1.3"
4646
rtic-monotonic = { version = "1.0", optional = true }
47+
systick-monotonic = { version = "1.0", optional = true }
4748
bitflags = "1.3.2"
4849
embedded-storage = "0.2"
4950

@@ -355,7 +356,7 @@ uart8 = []
355356
uart9 = []
356357
uart10 = []
357358

358-
rtic = ["rtic-monotonic"]
359+
rtic = ["rtic-monotonic", "systick-monotonic"]
359360

360361
[profile.dev]
361362
debug = true

src/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,7 @@ pub use crate::time::U32Ext as _stm32f4xx_hal_time_U32Ext;
7575
#[cfg(feature = "rtic")]
7676
pub use crate::timer::MonoTimerExt as _stm32f4xx_hal_timer_MonoTimerExt;
7777
pub use crate::timer::PwmExt as _stm32f4xx_hal_timer_PwmExt;
78+
#[cfg(feature = "rtic")]
79+
pub use crate::timer::SysMonoTimerExt as _stm32f4xx_hal_timer_SysMonoTimerExt;
7880
pub use crate::timer::SysTimerExt as _stm32f4xx_hal_timer_SysCounterExt;
7981
pub use crate::timer::TimerExt as _stm32f4xx_hal_timer_TimerExt;

src/timer/monotonic.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::rcc::Clocks;
44
use core::ops::{Deref, DerefMut};
55
pub use fugit::{self, ExtU32};
66
use rtic_monotonic::Monotonic;
7+
use systick_monotonic::Systick;
78

89
pub struct MonoTimer<TIM, const FREQ: u32>(FTimer<TIM, FREQ>);
910

@@ -48,6 +49,19 @@ where
4849
}
4950
}
5051

52+
pub trait SysMonoTimerExt: Sized {
53+
fn monotonic<const FREQ: u32>(self, clocks: &Clocks) -> Systick<FREQ>;
54+
fn monotonic_us(self, clocks: &Clocks) -> Systick<1_000_000> {
55+
self.monotonic::<1_000_000>(clocks)
56+
}
57+
}
58+
59+
impl SysMonoTimerExt for crate::pac::SYST {
60+
fn monotonic<const FREQ: u32>(self, clocks: &Clocks) -> Systick<FREQ> {
61+
Systick::new(self, clocks.hclk().raw())
62+
}
63+
}
64+
5165
impl<TIM, const FREQ: u32> FTimer<TIM, FREQ>
5266
where
5367
TIM: Instance + General<Width = u32> + WithPwm,

src/timer/pwm.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,18 @@ where
421421
TIM::read_cc_value(PINS::check_used(channel) as u8) as u16
422422
}
423423

424+
pub fn get_duty_time(&self, channel: Channel) -> TimerDurationU32<FREQ> {
425+
TimerDurationU32::from_ticks(TIM::read_cc_value(PINS::check_used(channel) as u8))
426+
}
427+
424428
pub fn set_duty(&mut self, channel: Channel, duty: u16) {
425429
TIM::set_cc_value(PINS::check_used(channel) as u8, duty.into())
426430
}
427431

432+
pub fn set_duty_time(&mut self, channel: Channel, duty: TimerDurationU32<FREQ>) {
433+
TIM::set_cc_value(PINS::check_used(channel) as u8, duty.ticks())
434+
}
435+
428436
/// If `0` returned means max_duty is 2^16
429437
pub fn get_max_duty(&self) -> u16 {
430438
(TIM::read_auto_reload() as u16).wrapping_add(1)

0 commit comments

Comments
 (0)