Skip to content

Commit 8edbbd8

Browse files
committed
docs
1 parent af79b3e commit 8edbbd8

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Bump `synopsys-usb-otg` to 0.3.2 (bug fix)
1313
- Update readme, clippy fixes
14-
- Added possibility to pass complementary pins to `Pwm` and change pwm channel polarity [#571]
14+
- Added possibility to pass complementary pins to `Pwm` and change pwm channel polarity [#571],
15+
set dead time and idle state for advanced timers [#578]
1516

1617
### Added
1718

@@ -27,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2728
[#571]: https://github.com/stm32-rs/stm32f4xx-hal/pull/571
2829
[#572]: https://github.com/stm32-rs/stm32f4xx-hal/pull/572
2930
[#577]: https://github.com/stm32-rs/stm32f4xx-hal/pull/577
31+
[#578]: https://github.com/stm32-rs/stm32f4xx-hal/pull/578
32+
3033

3134
## [v0.14.0] - 2022-12-12
3235

src/timer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub type CCR4<T> = CCR<T, 3>;
246246
pub struct DMAR<T>(T);
247247

248248
mod sealed {
249-
use super::{Channel, Event, Ocm, Polarity, IdleState};
249+
use super::{Channel, Event, IdleState, Ocm, Polarity};
250250
pub trait General {
251251
type Width: Into<u32> + From<u16>;
252252
fn max_auto_reload() -> u32;
@@ -485,11 +485,14 @@ macro_rules! hal {
485485
}
486486
fn idle_state(c: u8, comp: bool, s: IdleState) {
487487
let tim = unsafe { &*<$TIM>::ptr() };
488-
if !comp && (c < Self::CH_NUMBER) {
489-
unsafe { bb::write(&tim.cr2, c*2 + 8, s == IdleState::Set); }
490-
}
491-
if comp && (c < Self::COMP_CH_NUMBER) {
492-
unsafe { bb::write(&tim.cr2, c*2 + 9, s == IdleState::Set); }
488+
if !comp {
489+
if c < Self::CH_NUMBER {
490+
unsafe { bb::write(&tim.cr2, c*2 + 8, s == IdleState::Set); }
491+
}
492+
} else {
493+
if c < Self::COMP_CH_NUMBER {
494+
unsafe { bb::write(&tim.cr2, c*2 + 9, s == IdleState::Set); }
495+
}
493496
}
494497
}
495498
}

src/timer/pwm.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
//! and change their polarity with `set_polarity` and `set_complementary_polarity`.
3535
3636
use super::{
37-
compute_arr_presc, Advanced, Channel, FTimer, Instance, Ocm, Polarity, Timer, WithPwm, IdleState,
37+
compute_arr_presc, Advanced, Channel, FTimer, IdleState, Instance, Ocm, Polarity, Timer,
38+
WithPwm,
3839
};
3940
use crate::rcc::Clocks;
4041
use core::marker::PhantomData;
@@ -438,17 +439,31 @@ where
438439
TIM::enable_nchannel(PINS::check_complementary_used(channel) as u8, false)
439440
}
440441

442+
/// Set number DTS ticks during that complementary pin is `dead`
441443
#[inline]
442444
pub fn set_dead_time(&mut self, dts_ticks: u16) {
443445
let bits = pack_ceil_dead_time(dts_ticks);
444446
TIM::set_dtg_value(bits);
445447
}
446448

449+
/// Set raw dead time (DTG) bits
450+
#[inline]
451+
pub fn set_dead_time_bits(&mut self, bits: u8) {
452+
TIM::set_dtg_value(bits);
453+
}
454+
455+
/// Return dead time for complementary pins in DTS ticks
447456
#[inline]
448457
pub fn get_dead_time(&self) -> u16 {
449458
unpack_dead_time(TIM::read_dtg_value())
450459
}
451460

461+
/// Get raw dead time (DTG) bits
462+
#[inline]
463+
pub fn get_dead_time_bits(&self) -> u8 {
464+
TIM::read_dtg_value()
465+
}
466+
452467
#[inline]
453468
pub fn set_idle_state(&mut self, channel: Channel, s: IdleState) {
454469
TIM::idle_state(PINS::check_used(channel) as u8, false, s);
@@ -626,17 +641,31 @@ where
626641
TIM::enable_nchannel(PINS::check_complementary_used(channel) as u8, false)
627642
}
628643

644+
/// Set number DTS ticks during that complementary pin is `dead`
629645
#[inline]
630646
pub fn set_dead_time(&mut self, dts_ticks: u16) {
631647
let bits = pack_ceil_dead_time(dts_ticks);
632648
TIM::set_dtg_value(bits);
633649
}
634650

651+
/// Set raw dead time (DTG) bits
652+
#[inline]
653+
pub fn set_dead_time_bits(&mut self, bits: u8) {
654+
TIM::set_dtg_value(bits);
655+
}
656+
657+
/// Return dead time for complementary pins in DTS ticks
635658
#[inline]
636659
pub fn get_dead_time(&self) -> u16 {
637660
unpack_dead_time(TIM::read_dtg_value())
638661
}
639662

663+
/// Get raw dead time (DTG) bits
664+
#[inline]
665+
pub fn get_dead_time_bits(&self) -> u8 {
666+
TIM::read_dtg_value()
667+
}
668+
640669
#[inline]
641670
pub fn set_idle_state(&mut self, channel: Channel, s: IdleState) {
642671
TIM::idle_state(PINS::check_used(channel) as u8, false, s);

0 commit comments

Comments
 (0)