Issue #2059 use write_immediate. Add docs. Remove half-write workaround
This commit is contained in:
parent
e35c1b494a
commit
376eb101f7
@ -876,6 +876,18 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> {
|
||||
self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow()));
|
||||
}
|
||||
|
||||
/// Write elements directly to the raw buffer.
|
||||
/// This can be used to fill the buffer before starting the DMA transfer.
|
||||
pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
|
||||
self.ringbuf.write_immediate(
|
||||
&mut DmaCtrlImpl {
|
||||
channel: self.channel.reborrow(),
|
||||
word_size: W::size(),
|
||||
},
|
||||
buf,
|
||||
)
|
||||
}
|
||||
|
||||
/// Write elements from the ring buffer
|
||||
/// Return a tuple of the length written and the length remaining in the buffer
|
||||
pub fn write(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
|
||||
|
@ -731,8 +731,10 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn prime(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
|
||||
self.ringbuf.prime(
|
||||
/// Write elements directly to the raw buffer.
|
||||
/// This can be used to fill the buffer before starting the DMA transfer.
|
||||
pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
|
||||
self.ringbuf.write_immediate(
|
||||
&mut DmaCtrlImpl {
|
||||
channel: self.channel.reborrow(),
|
||||
word_size: W::size(),
|
||||
|
@ -260,15 +260,11 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> {
|
||||
|
||||
/// The current position of the ringbuffer
|
||||
fn pos(&self, dma: &mut impl DmaCtrl) -> usize {
|
||||
let result = self.cap() - dma.get_remaining_transfers();
|
||||
if result >= self.cap() / 2 {
|
||||
self.cap() / 2
|
||||
} else {
|
||||
0
|
||||
}
|
||||
self.cap() - dma.get_remaining_transfers()
|
||||
}
|
||||
|
||||
pub fn prime(&mut self, dma: &mut impl DmaCtrl, buffer: &[W]) -> Result<(usize, usize), OverrunError> {
|
||||
/// Write elements directl to the buffer. This should be done before the DMA is started.
|
||||
pub fn write_immediate(&mut self, dma: &mut impl DmaCtrl, buffer: &[W]) -> Result<(usize, usize), OverrunError> {
|
||||
if self.end != 0 {
|
||||
return Err(OverrunError);
|
||||
}
|
||||
|
@ -435,6 +435,8 @@ impl MasterClockDivider {
|
||||
}
|
||||
}
|
||||
|
||||
pub const MAX_FRAME_LENGTH: u8 = 0;
|
||||
|
||||
/// [`SAI`] configuration.
|
||||
#[non_exhaustive]
|
||||
#[derive(Copy, Clone)]
|
||||
@ -853,13 +855,6 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prime(self: &mut Self, prime_buffer: &[W]) -> Result<(usize, usize), Error> {
|
||||
match self.ring_buffer {
|
||||
RingBuffer::Writable(ref mut rb) => Ok(rb.prime(prime_buffer)?),
|
||||
RingBuffer::Readable(_) => Err(Error::NotATransmitter),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_transmitter(ring_buffer: &RingBuffer<C, W>) -> bool {
|
||||
match ring_buffer {
|
||||
RingBuffer::Writable(_) => true,
|
||||
@ -943,7 +938,11 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> {
|
||||
w.set_fspol(config.frame_sync_polarity.fspol());
|
||||
w.set_fsdef(config.frame_sync_definition.fsdef());
|
||||
w.set_fsall(config.frame_sync_active_level_length.0 as u8 - 1);
|
||||
w.set_frl(config.frame_length - 1);
|
||||
if config.frame_length == MAX_FRAME_LENGTH {
|
||||
w.set_frl(255);
|
||||
} else {
|
||||
w.set_frl(config.frame_length - 1);
|
||||
}
|
||||
});
|
||||
|
||||
ch.slotr().modify(|w| {
|
||||
@ -1030,6 +1029,16 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Write elements directly to the raw buffer.
|
||||
/// This should be used before starting the audio stream. This will give the CPU time to
|
||||
/// prepare the next audio frame while the initial audio frame is playing.
|
||||
pub fn write_immediate(self: &mut Self, source_buffer: &[W]) -> Result<(usize, usize), Error> {
|
||||
match self.ring_buffer {
|
||||
RingBuffer::Writable(ref mut rb) => Ok(rb.write_immediate(source_buffer)?),
|
||||
RingBuffer::Readable(_) => Err(Error::NotATransmitter),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn write(&mut self, data: &[W]) -> Result<(), Error> {
|
||||
match &mut self.ring_buffer {
|
||||
RingBuffer::Writable(buffer) => {
|
||||
|
Loading…
Reference in New Issue
Block a user