Skip to content

Commit a36577c

Browse files
bors[bot]samcrow
andauthored
Merge #314
314: Add open-drain pin mode support for PWM output r=therealprof a=samcrow ### Motivation ATX-compatible fans have PWM speed control inputs that they internally pull up (to 5.2.5 V maximum). To correctly control the speed of these fans, a microcontroller needs to generate a PWM signal with a pin in open-drain mode. ### Changes This pull request makes the PWM code support `AlternateOD` mode in addition to `Alternate` mode for all currently supported pins. Co-authored-by: Sam Crow <scrow@eng.ucsd.edu>
2 parents 1ad01fe + dd09902 commit a36577c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1818
- Added an example for using the new FSMC interface with the provided
1919
`display-interface` driver and the `st7789` driver on a F413Discovery board [#302]
2020
- Derive `Eq`, `PartialEq`, `Copy` and `Clone` for error types
21+
- Added open-drain pin mode support for PWM output [#313]
2122

2223
[#265]: https://github.com/stm32-rs/stm32f4xx-hal/pull/265
2324
[#297]: https://github.com/stm32-rs/stm32f4xx-hal/pull/297
2425
[#302]: https://github.com/stm32-rs/stm32f4xx-hal/pull/302
26+
[#313]: https://github.com/stm32-rs/stm32f4xx-hal/pull/313
2527

2628
### Changed
2729

src/timer.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//! Timers
2+
//!
3+
//! Pins can be used for PWM output in both push-pull mode (`Alternate`) and open-drain mode
4+
//! (`AlternateOD`).
25
36
use cast::{u16, u32};
47
use cortex_m::peripheral::syst::SystClkSource;
@@ -626,7 +629,7 @@ use crate::gpio::AF2;
626629
))]
627630
use crate::gpio::AF3;
628631

629-
use crate::gpio::{gpioa::*, Alternate};
632+
use crate::gpio::{gpioa::*, Alternate, AlternateOD};
630633

631634
// Output channels marker traits
632635
pub trait PinC1<TIM> {}
@@ -637,7 +640,8 @@ pub trait PinC4<TIM> {}
637640
macro_rules! channel_impl {
638641
( $( $TIM:ident, $PINC:ident, $PINX:ident, $MODE:ident<$AF:ident>; )+ ) => {
639642
$(
640-
impl $PINC<$TIM> for $PINX<$MODE<$AF>> {}
643+
impl $PINC<$TIM> for $PINX<Alternate<$AF>> {}
644+
impl $PINC<$TIM> for $PINX<AlternateOD<$AF>> {}
641645
)+
642646
};
643647
}

0 commit comments

Comments
 (0)