|
| 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 | +
|
1 | 36 | 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, |
3 | 38 | };
|
4 | 39 | use crate::rcc::Clocks;
|
5 | 40 | use core::marker::PhantomData;
|
@@ -43,7 +78,7 @@ pub trait Pins<TIM, P> {
|
43 | 78 |
|
44 | 79 | fn split() -> Self::Channels;
|
45 | 80 | }
|
46 |
| -pub use super::{CPin, Ch, C1, C2, C3, C4}; |
| 81 | +pub use super::{CPin, Ch, NCPin, C1, C2, C3, C4}; |
47 | 82 |
|
48 | 83 | pub struct PwmChannel<TIM, const C: u8, const COMP: bool = false> {
|
49 | 84 | pub(super) _tim: PhantomData<TIM>,
|
|
0 commit comments