aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp
diff options
context:
space:
mode:
authorRiley Williams <[email protected]>2023-10-17 19:05:35 -0400
committerGitHub <[email protected]>2023-10-17 19:05:35 -0400
commit3f262a26036c84e41e8c0144f2ffae3e64614bd2 (patch)
tree6b6e1344cd44e5f58d0da77bc31c2c8e0cc4a281 /embassy-rp
parentd94b9fe6fb6adee82c1427e72450f77a0d0973c3 (diff)
Add docs to RP2040 PWM
Diffstat (limited to 'embassy-rp')
-rw-r--r--embassy-rp/src/pwm.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs
index c297d69a2..ff19bcf48 100644
--- a/embassy-rp/src/pwm.rs
+++ b/embassy-rp/src/pwm.rs
@@ -10,16 +10,40 @@ use crate::gpio::sealed::Pin as _;
10use crate::gpio::{AnyPin, Pin as GpioPin}; 10use crate::gpio::{AnyPin, Pin as GpioPin};
11use crate::{pac, peripherals, RegExt}; 11use crate::{pac, peripherals, RegExt};
12 12
13/// The configuration of a PWM slice.
14///Note the period in clock cycles of a slice can be computed as:
15/// (top + 1) * (phase_correct ? 1 : 2) * divider
13#[non_exhaustive] 16#[non_exhaustive]
14#[derive(Clone)] 17#[derive(Clone)]
15pub struct Config { 18pub struct Config {
19 /// Inverts the PWM output signal on channel A.
16 pub invert_a: bool, 20 pub invert_a: bool,
21 /// Inverts the PWM output signal on channel B.
17 pub invert_b: bool, 22 pub invert_b: bool,
23 /// Enables phase-correct mode for PWM operation.
24 /// In phase-correct mode, the PWM signal is generated in such a way that
25 /// the pulse is always centered regardless of the duty cycle.
26 /// The output frequency is halved when phase-correct mode is enabled.
18 pub phase_correct: bool, 27 pub phase_correct: bool,
28 /// Enables the PWM slice, allowing it to generate an output.
29 /// When disabled, the PWM slice will not produce any output.
19 pub enable: bool, 30 pub enable: bool,
31 /// A fractional clock divider, represented as a fixed-point number with
32 /// 8 integer bits and 4 fractional bits. It allows precise control over
33 /// the PWM output frequency by gating the PWM counter increment.
34 /// A higher value will result in a slower output frequency.
20 pub divider: fixed::FixedU16<fixed::types::extra::U4>, 35 pub divider: fixed::FixedU16<fixed::types::extra::U4>,
36 /// The output on channel A goes high when `compare_a` is higher than the
37 /// counter. A compare of 0 will produce an always low output, while a
38 /// compare of `top` + 1 will produce an always high output.
21 pub compare_a: u16, 39 pub compare_a: u16,
40 /// The output on channel B goes high when `compare_b` is higher than the
41 /// counter. A compare of 0 will produce an always low output, while a
42 /// compare of `top` + 1 will produce an always high output.
22 pub compare_b: u16, 43 pub compare_b: u16,
44 /// The point at which the counter wraps, representing the maximum possible
45 /// period. The counter will either wrap to 0 or reverse depending on the
46 /// setting of `phase_correct`.
23 pub top: u16, 47 pub top: u16,
24} 48}
25 49
@@ -173,6 +197,9 @@ impl<'d, T: Channel> Pwm<'d, T> {
173 }); 197 });
174 } 198 }
175 199
200 /// Advances a slice’s output phase by one count while it is running
201 /// by inserting or deleting pulses from the clock enable. The counter
202 /// will not count faster than once per cycle.
176 #[inline] 203 #[inline]
177 pub fn phase_advance(&mut self) { 204 pub fn phase_advance(&mut self) {
178 let p = self.inner.regs(); 205 let p = self.inner.regs();
@@ -180,6 +207,9 @@ impl<'d, T: Channel> Pwm<'d, T> {
180 while p.csr().read().ph_adv() {} 207 while p.csr().read().ph_adv() {}
181 } 208 }
182 209
210 /// Retards a slice’s output phase by one count while it is running
211 /// by deleting pulses from the clock enable. The counter will not
212 /// count backward when clock enable is permenantly low
183 #[inline] 213 #[inline]
184 pub fn phase_retard(&mut self) { 214 pub fn phase_retard(&mut self) {
185 let p = self.inner.regs(); 215 let p = self.inner.regs();