aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/ringbuffered.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/timer/ringbuffered.rs')
-rw-r--r--embassy-stm32/src/timer/ringbuffered.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/embassy-stm32/src/timer/ringbuffered.rs b/embassy-stm32/src/timer/ringbuffered.rs
index bb602f8a7..e8f97bf59 100644
--- a/embassy-stm32/src/timer/ringbuffered.rs
+++ b/embassy-stm32/src/timer/ringbuffered.rs
@@ -5,9 +5,24 @@ use core::task::Waker;
5 5
6use super::low_level::Timer; 6use super::low_level::Timer;
7use super::{Channel, GeneralInstance4Channel}; 7use super::{Channel, GeneralInstance4Channel};
8use crate::dma::ringbuffer::Error;
9use crate::dma::WritableRingBuffer; 8use crate::dma::WritableRingBuffer;
9use crate::dma::ringbuffer::Error;
10 10
11/// A PWM channel that uses a DMA ring buffer for continuous waveform generation.
12///
13/// This allows you to continuously update PWM duty cycles via DMA without blocking the CPU.
14/// The ring buffer enables smooth, uninterrupted waveform generation by automatically cycling
15/// through duty cycle values stored in memory.
16///
17/// You can write new duty cycle values to the ring buffer while it's running, enabling
18/// dynamic waveform generation for applications like motor control, LED dimming, or audio output.
19///
20/// # Example
21/// ```ignore
22/// let mut channel = pwm.ch1().into_ring_buffered_channel(dma_ch, &mut buffer);
23/// channel.start(); // Start DMA transfer
24/// channel.write(&[100, 200, 300]).ok(); // Update duty cycles
25/// ```
11pub struct RingBufferedPwmChannel<'d, T: GeneralInstance4Channel> { 26pub struct RingBufferedPwmChannel<'d, T: GeneralInstance4Channel> {
12 timer: ManuallyDrop<Timer<'d, T>>, 27 timer: ManuallyDrop<Timer<'d, T>>,
13 ring_buf: WritableRingBuffer<'d, u16>, 28 ring_buf: WritableRingBuffer<'d, u16>,
@@ -15,7 +30,11 @@ pub struct RingBufferedPwmChannel<'d, T: GeneralInstance4Channel> {
15} 30}
16 31
17impl<'d, T: GeneralInstance4Channel> RingBufferedPwmChannel<'d, T> { 32impl<'d, T: GeneralInstance4Channel> RingBufferedPwmChannel<'d, T> {
18 pub(crate) fn new(timer: ManuallyDrop<Timer<'d, T>>, channel: Channel, ring_buf: WritableRingBuffer<'d, u16>) -> Self { 33 pub(crate) fn new(
34 timer: ManuallyDrop<Timer<'d, T>>,
35 channel: Channel,
36 ring_buf: WritableRingBuffer<'d, u16>,
37 ) -> Self {
19 Self { 38 Self {
20 timer, 39 timer,
21 ring_buf, 40 ring_buf,
@@ -148,5 +167,3 @@ pub struct RingBufferedPwmChannels<'d, T: GeneralInstance4Channel> {
148 /// Channel 4 167 /// Channel 4
149 pub ch4: RingBufferedPwmChannel<'d, T>, 168 pub ch4: RingBufferedPwmChannel<'d, T>,
150} 169}
151
152