Skip to content

Commit 5c059c2

Browse files
committed
some more docs
1 parent 3593700 commit 5c059c2

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/timer/pwm.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
1+
//! Provides basic Pulse-width modulation (PWM) capabilities
2+
//!
3+
//! There are 2 main stuctures [`Pwm`] and [`PwmHz`]. Both structures implement [`embedded_hal::Pwm`] and have some additional API.
4+
//!
5+
//! First one is based on [`FTimer`] with fixed prescaler
6+
//! and easy to use with [`fugit::TimerDurationU32`] for setting pulse width and period without advanced calculations.
7+
//!
8+
//! Second one is based on [`Timer`] with dynamic internally calculated prescaler and require [`fugit::Hertz`] to set period.
9+
//!
10+
//! You can [`split`](Pwm::split) any of those structures on independent `PwmChannel`s if you need that implement [`embedded_hal::PwmPin`]
11+
//! but can't change PWM period.
12+
//!
13+
//! Also there is [`PwmExt`] trait implemented on `pac::TIMx` to simplify creating new structure.
14+
//!
15+
//! You need to pass pins you plan to use and initial `time`/`frequency` corresponding PWM period.
16+
//! Pins can be collected in tuples in sequence corresponding to the channel number. Smaller channel number first.
17+
//! Each channel group can contain 1 or several main pins and 0, 1 or several complementary pins. Main pins first.
18+
//!
19+
//! For example:
20+
//! ```plain,ignore
21+
//! ( (CH1, CHN1), CH2, ( (CH3_1, CH3_2), CHN3 ) )
22+
//! | chan. 1 | |chan. 2| | chan. 3 |
23+
//! ```
24+
//! or
25+
//! ```rust,ignore
26+
//! let channels = (gpioa.pa7.into_alternate(), gpioa.pa8.into_alternate()); // error: (CHN1, CH1)
27+
//!
28+
//! let channels = (gpioa.pa8.into_alternate(), gpioa.pa7.into_alternate()); // good: (CH1, CHN1)
29+
//! ```
30+
//!
31+
//! where `CHx` and `CHx_n` are main pins of PWM channel `x` and `CHNx` are complementary pins of PWM channel `x`.
32+
//!
33+
//! After creating structures you can dynamically enable main or complementary channels with `enable` and `enable_complementary`
34+
//! and change their polarity with `set_polarity` and `set_complementary_polarity`.
35+
136
use super::{
2-
compute_arr_presc, Advanced, Channel, FTimer, Instance, NCPin, Ocm, Polarity, Timer, WithPwm,
37+
compute_arr_presc, Advanced, Channel, FTimer, Instance, Ocm, Polarity, Timer, WithPwm,
338
};
439
use crate::rcc::Clocks;
540
use core::marker::PhantomData;
@@ -43,7 +78,7 @@ pub trait Pins<TIM, P> {
4378

4479
fn split() -> Self::Channels;
4580
}
46-
pub use super::{CPin, Ch, C1, C2, C3, C4};
81+
pub use super::{CPin, Ch, NCPin, C1, C2, C3, C4};
4782

4883
pub struct PwmChannel<TIM, const C: u8, const COMP: bool = false> {
4984
pub(super) _tim: PhantomData<TIM>,

0 commit comments

Comments
 (0)