Merge pull request #2397 from tyler-gilbert/add-write-immediate-api-dma-ring-buffer
Add write_immediate() function to STM32 DMA ringbufer API
This commit is contained in:
		
						commit
						1641f8a27e
					
				@ -664,6 +664,13 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> {
 | 
				
			|||||||
        self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow()));
 | 
					        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.
 | 
				
			||||||
 | 
					    #[allow(dead_code)]
 | 
				
			||||||
 | 
					    pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
 | 
				
			||||||
 | 
					        self.ringbuf.write_immediate(buf)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Write elements to the ring buffer
 | 
					    /// Write elements to the ring buffer
 | 
				
			||||||
    /// Return a tuple of the length written and the length remaining in the 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> {
 | 
					    pub fn write(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
 | 
				
			||||||
 | 
				
			|||||||
@ -934,6 +934,13 @@ impl<'a, C: Channel, W: Word> WritableRingBuffer<'a, C, W> {
 | 
				
			|||||||
        self.ringbuf.clear(&mut DmaCtrlImpl(self.channel.reborrow()));
 | 
					        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.
 | 
				
			||||||
 | 
					    #[allow(dead_code)]
 | 
				
			||||||
 | 
					    pub fn write_immediate(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
 | 
				
			||||||
 | 
					        self.ringbuf.write_immediate(buf)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Write elements from the ring buffer
 | 
					    /// Write elements from the ring buffer
 | 
				
			||||||
    /// Return a tuple of the length written and the length remaining in the 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> {
 | 
					    pub fn write(&mut self, buf: &[W]) -> Result<(usize, usize), OverrunError> {
 | 
				
			||||||
 | 
				
			|||||||
@ -263,6 +263,17 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> {
 | 
				
			|||||||
        self.cap() - dma.get_remaining_transfers()
 | 
					        self.cap() - dma.get_remaining_transfers()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Write elements directly to the buffer. This must be done before the DMA is started
 | 
				
			||||||
 | 
					    /// or after the buffer has been cleared using `clear()`.
 | 
				
			||||||
 | 
					    pub fn write_immediate(&mut self, buffer: &[W]) -> Result<(usize, usize), OverrunError> {
 | 
				
			||||||
 | 
					        if self.end != 0 {
 | 
				
			||||||
 | 
					            return Err(OverrunError);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let written = self.copy_from(buffer, 0..self.cap());
 | 
				
			||||||
 | 
					        self.end = written % self.cap();
 | 
				
			||||||
 | 
					        Ok((written, self.cap() - written))
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Write an exact number of elements to the ringbuffer.
 | 
					    /// Write an exact number of elements to the ringbuffer.
 | 
				
			||||||
    pub async fn write_exact(&mut self, dma: &mut impl DmaCtrl, buffer: &[W]) -> Result<usize, OverrunError> {
 | 
					    pub async fn write_exact(&mut self, dma: &mut impl DmaCtrl, buffer: &[W]) -> Result<usize, OverrunError> {
 | 
				
			||||||
        let mut written_data = 0;
 | 
					        let mut written_data = 0;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user